note 11672 modified in Classes and Objects by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Thu, 01 Mar 2001 23:18:51 +0000 |
| Subject: | note 11672 modified in Classes and Objects by jmcastagnetto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11752@lists.php.net to get a copy of this message | ||
[Editor's note: I have coalesced the series of notes into one, and will just make the following
comments. The code belows has 2 glaring problems:
1) it is using a reserved word for a method name, and until the language support namespaces, this is
incorrect
2) the methods from an object should have a function style call, not an attribute style, i.e.
$object->method();
If the code is changed to read:
class foo {
var $var;
function foo() {
$this->var = true;
}
function p() {
print($this->var);
for ($i = 0; $i < 5; $i++) {
print($this->var);
}
}
}
$class = new foo;
$class->p();
It works as intended. ]
You cannot get object values in a for loop in a class:
class foo {
var $var;
function foo() {
$this->var = true;
}
function print() {
print($this->var); //Will work
for ($i = 0; $i < 5; $i++) {
print($this->var); //Will NOT work
}
}
}
$class = new foo;
$class->print;
[and then the author posted]
teriumNOSPAM@techie.com
01-Mar-2001 05:53pm
Erase my previous post. I'm an idiot =)
[and subsequently also]
teriumNOSPAM@techie.com
01-Mar-2001 05:54pm
Actually, don't erase it.. it didn't work
http://www.php.net/manual/classes-and-objects.php