|
Posted by raf on 09/17/05 13:57
www.douglassdavis.com wrote:
> All three of the following classes give "compile-time" errors. It
> hinders me from doing what I want to do... And it seems there is no way
> around it. But, are each of these cases examples of how the language
> should behave? Are any of the examples a case of PHP being
> "incorrect?"
I don't know PHP, but I believe these are bugs in your code:
> class MyClass
> {
> static $x = 2;
> static $y = self::$x; // error
> }
there is no instantiation of the class--there is no "self" object.
Did you mean "static $y = $x"?
> class MyClass2
> {
> var $x = 2;
> static $y = $x; // error
> }
In this case, since no object was created, there is no $x to assign into
$y.
> class MyClass3
> {
> const a = array(1,2); // error
> }
I defer this to someone who knows PHP, but if its semantics are
comparable to Java and C#, does "array(1,2)" actually create an instance
of an array? Based on the pattern of the errors above, I'd suggest you
review the concepts of object instantiation and class/instance member
variables.
raf
Navigation:
[Reply to this message]
|