note 9032 added to Classes and Objects
| From: | mircho at abv dot bg | Date: | Thu, 12 Oct 2000 10:19:42 +0000 |
| Subject: | note 9032 added to Classes and Objects | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-6407@lists.php.net to get a copy of this message | ||
A short comment on classes [this maybe is an answer on some previous posts.
In PHP4 [I havent tested it on PHP3]
You can't have executable code within the class declaration. Here is what I mean:
define( MY_VAR_1, 4 )
define( MY_VAR_2, 15 )
class classMyWork
{
var $nClassVar = MY_VAR_1*MY_VAR_2;
var $nClassVar = MY_VAR_1*10;
//BOTH WON'T WORK
var $hOtherClass = new classOtherClass();
//THIS WON'T WORK TOO
}
Obvoiously there's no syntactic sugar as found in Java or C++
All initialization should be performed in the class constructor
And maybe the assignment of a global variable to a class member is the same problem
http://www.php.net/manual/language.oop.php