|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-04-07 18:31 UTC] vdhome at idas dot cz
I am not sure whether this is a bug, a feature, or lack of a feature. Perhaps this should be marked a "Feature Request" then... Anyway, here goes: the var declaration in a class seems to have no meaning whatsoever, except perhaps for documentation purposes. PHP allows me to assign to class variables that weren't declared without even a warning at the highest warning reporting level. That's actually not very surprising since PHP doesn't otherwise have declarations of variables, but what is then the meaning of var in classes? I suggest that PHP should at least warn about class variables that weren't declared. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 19:00:02 2025 UTC |
So is it (and will it continue to be) valid to use/create class variables not explicitly declared with var? Currently the following produce the excact same results except that the varaible 'a' will not be returned by get_class_vars. class foo { var $a; function foo() { $this->a = "test"; } }; class foo2 { function foo2() { $this->a = "test"; } };<? /** * A bugg in php? */ class One { var $a; var $b; /** Print $a & $b */ function printVars() { echo("Vareabels: <BR>\n"); echo("\$a: " . $this->$a . "<BR>\n"); echo("\$b: " . $this->$b . "<BR>\n"); } } class Two extends One { function Two() { $this->$a = "A"; $this->$b = "B"; $this->printVars(); } } $two = new Two; echo("<BR>\n"); print_r(get_object_vars($two)); ?> This code gave the result: Vareabels: $a: B $b: B Array ( [a] => [b] => [] => B ) Should to work this way?