Newbie: classes help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gen23
Forum Newbie
Posts: 7
Joined: Fri Apr 08, 2005 10:13 am

Newbie: classes help...

Post by gen23 »

Hi,

Can anyone please explain what this statement means?

Code: Select all

class & execute (&$controller, &$request, &$user)
{
$renderer =& new renderer ($controller, $request, $user);
}
or even this one:

Code: Select all

class first_class
{
$obj1 = new first_class(); 
$obj2 = new first_class();
}
Thank you in advance...

Phenom | Please use

Code: Select all

Tags[/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

& is used to reference things, and your classes are creating new objects.

For example

$obj1 = new first_class();

You have now created an object which instantiates your class. Although it does not make sense to instantiate your class inside the class, because it must already be done to use the class. Unless of course it is static.

Your first example uses reference.

$var = 'blah';

$var2 &= $var now references to $var
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ya, using the & makes the operation a reference, rather than an equality. If you use =&, you are essentially making a new shortcut to the value. For example:

Code: Select all

$x = 2;
$y = $x;
$z =& $x;

$x++;

echo $y . '|' . $z;
... would echo '2|3'.

Code: Select all

$x = 2;
$z =& $x;

$z++;
echo $x;
... would echo '3' again.

Using the =& operator just allows another variable name to be pointed to the value of the first variable. Essentially, you'll have two pointers to the same data.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply