Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

whats ->

Status
Not open for further replies.

jain747

Technical User
Apr 22, 2003
17
US
I'm trying to understand code about heredoc notation from the PHP manual, but I can't figure out what -> means in $this->foo = 'Foo'; I dont think the previous chapters have discussed the usage of ->. Thanks for the help.


<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

/* More complex example, with variables. */
class foo
{
var $foo;
var $bar;

function foo()
{
$this->foo = 'Foo';
$this->bar = array('Bar1', 'Bar2', 'Bar3');
}
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is &quot;$name&quot;. I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>
 
Your accessing the member of a class.
Code:
You see the 
var $foo;

above?  

so 
$this->foo = 'Foo';

means your modifying that private member.

New instances of a class foo will each have their own copy of $foo inside them.  Using this->foo is what tells it that it's modifying it's own copy, rather than some global variable outside the class.

That is far from the best explanation, but my OO skills are weak.  G'luck.
-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top