Re: PHP 4.0 Bug #8141 Updated: "define" as array index in class definition is ignored
| From: | Lars Torben Wilson | Date: | Thu, 07 Dec 2000 17:30:02 +0000 |
| Subject: | Re: PHP 4.0 Bug #8141 Updated: "define" as array index in class definition is ignored | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-40328@lists.php.net to get a copy of this message | ||
stas@php.net writes:
> ID: 8141
> Updated by: stas
> Reported By: hp@oeri.ch
> Status: Analyzed
> Bug Type: Class/Object related
> Assigned To:
> Comments:
>
> Actually, it is a bug. It doesn't give any error, produces
> undesired behaviour and leaks memory. This should be fixed
> either way - or give warning/error, or work - and in either
> case not to leak.
Yeah, after a couple of offlist emails, I figured that this would be
something that could use an error message. If what I gleaned after a
closer look is correct, then the problem is that the value of the
named constant, in this case 'ABC', cannot presently be known at
compile time, as is apparently required by the class initializer bit
in zend_language_parser.y.
It looked like a check would need to be made on every array index in
order to know whether the key or value was not known at compile time,
if an error message were to be generated. That's where I stopped
looking; someone with a better understanding of the parser will need
to take it farther. :)
I was thinking about reclassifying this as a Feature Request for such
an error message. As it is, it's a tough problem to track down.
> Previous Comments:
> ---------------------------------------------------------------------------
>
> [2000-12-06 17:31:22] torben@php.net
> Not a bug. Class variable initializers must be static; do this
> in the constructor instead.
>
> Check out the text in the manual right after the first example
> on the Classes page:
>
> http://www.php.net/manual/language.oop.php
>
>
> Hope this helps,
>
> Torben
>
> ---------------------------------------------------------------------------
>
> [2000-12-06 16:36:07] hp@oeri.ch
> In the snippet below, the array entry "ABC"=>1 is simply ignored. An array
> OUTSIDE of a class definition is fine!
>
> <?
> define( "ABC", 8 );
>
> class test {
> var $t = array( ABC => 1, 2 => 3 );
> }
>
> $u = New test();
>
> var_dump( $u );
> ?>
>
> ---------------------------------------------------------------------------
>
>
> Full Bug description available at: http://bugs.php.net/?id=8141
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+