Strange class behavior
| From: | Harsanyi Alexandru | Date: | Wed, 19 Jul 2000 15:32:27 +0000 |
| Subject: | Strange class behavior | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7236@lists.php.net to get a copy of this message | ||
Hi,
I'm relatively new to PHP and I got stuck at using classes and objects
in PHP.
Here is an example:
---------------------
<html>
<head></head>
<body>
<?php
class node
{
var $id, $name;
function node($theId, $theName)
{
$this->$id = $theId;
$this->$name = $theName;
}
}
$n = new node(1, "some_node");
echo "Node id is: " . $n->$id;
?>
</body>
</html>
--------------------------
A class is declared with an $id and a $name members. The constructor
initializes them.
However, when I run the script, I get the following ansver:
Node id is: some_node
although I referenced $n->$id, which was initialized in the constructor
to 1.
What am I missing here?
BTW, what does the "var" keyword do? If I remove the "var" line I don't
notice any difference....
Best Regards,
Alex.