TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-29-2008, 05:01 PM   #1 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default OOP 4.0 -> 5.0 reference

Sup.

Hmm, I was scrolling through a very nice document about GPS PHP tracking and tracing and we came across two very stange variables. An instance defined and a variable in a function or class.

PHP Code:
class mySQL {
    function 
foobar $foo, &$bar) {
       
$this->foo $foo;
        
$this->bar = &$bar;
    }

Anyways, I think you get my drift. Same goes for a class that directly calls to a function, correct me if I am wrong but this is how I, sort of, remember it.
echo instanceName::&variable->foo;

So, could somebody explain those combinations? Same goes for:
PHP Code:
$foo $bar;
$wtf =& $bar
And a little example of the above:
PHP Code:
$a = new A();
$a->foo();
A::foo();
$b = new B();
$b->bar();
B::bar(); 
Source: PHP: The Basics - Manual
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 04-29-2008, 05:26 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Hmm, not sure if I followed you there, but if I did, I think you're asking about a) references (the & signed being used there), and b) Paamayim Nekudotayim, aka the scope resolution operator used to access static methods of a class, or to (as is allowed for some reason) simply access a public method of that class without creating a new instance of said class.

PHP Code:
class staticReference
{
    static 
$var;

    static function 
setVar ($var) {
        
self::$var $var;
    }
// staticReference

staticReference::setVar("dude!");
$reference =& staticReference::$var;

echo 
staticReference::$var;
echo 
$reference;

staticReference::setVar("totally.");
echo 
$reference;

$reference "whoah.";
echo 
staticReference::$var
If I gathered what you were asking correctly, that should be a good demonstration of what's going on. If not, I probably look pretty dumb right now.

staticReference has two parts, a static variable and a method that you can use to set that variable. Both are declared static, so are meant to be used with the scope resolution operator (::), without having to call an instance of the class into existence. Notice how the methods are all being called, but a new statement has never been made?

As for the reference, it creates a pointer of sorts to the original data. If you make a reference to staticReference::$var, whenever you change staticReference::$var, so does the reference you created since it's pointing to the original data, and not a copy of it. Same goes visa versa, it's all accessing the same data.

Did that help at all? It's early here.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-30-2008, 08:02 PM   #3 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

It's a lot to take in, considering that's all new to me (OOP5) but I think I'll manage. If not, the questions will be asked here of course.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:05 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design