[PHP-DEV] Unexpected behavior for ::
Hello, I'm not sure if this is the desired behavior and i don't want to submit a bogus bug report. class A { public function f1() { var_dump($this-_b); } } class B { public $_b = 'stuff'; public function f2() { A::f1(); } } $b = new B(); $b-f2(); At first i would expect an error since A was not instantiated, at most i would expect to return NULL but not 'stuff'. Is this a bug ? -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior for ::
I'm not sure if this is the desired behavior and i don't want to submit a bogus bug report. … At first i would expect an error since A was not instantiated, at most i would expect to return NULL but not 'stuff'. Is this a bug ? This is explained here: http://php.net/language.oop5.basic#example-155 (the paragraph after this example, and in example #2) S -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior for ::
Hi, On Mon, Dec 12, 2011 at 14:35, Bogdan Bezuz bogdan.be...@emag.ro wrote: Hello, I'm not sure if this is the desired behavior and i don't want to submit a bogus bug report. class A { public function f1() { var_dump($this-_b); } } class B { public $_b = 'stuff'; public function f2() { A::f1(); } } $b = new B(); $b-f2(); At first i would expect an error since A was not instantiated, at most i would expect to return NULL but not 'stuff'. Is this a bug ? Not really, it's a BC compatibility that we had to drag since PHP4. If you enable E_STRICT, it should output a warning saying something like importing $this from invalid context. It is/was scheduled for cleanup in the next major version. Best, -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- Etienne Kneuss http://www.colder.ch -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior for ::
Hello, Thanks for the info, as pointed out by Sean Coates this is sort of documented, I've submited a documentation (problem/)bug report. https://bugs.php.net/bug.php?id=60499 E_STRICT was disabled since a large part of the application was moved to php 5 only last year and, even if i was aware that it is possible to call non-static methods in a static way, i didn't expect this to work. On 12/12/2011 16:12, Etienne Kneuss wrote: Hi, On Mon, Dec 12, 2011 at 14:35, Bogdan Bezuz bogdan.be...@emag.ro wrote: Hello, I'm not sure if this is the desired behavior and i don't want to submit a bogus bug report. class A { public function f1() { var_dump($this-_b); } } class B { public $_b = 'stuff'; public function f2() { A::f1(); } } $b = new B(); $b-f2(); At first i would expect an error since A was not instantiated, at most i would expect to return NULL but not 'stuff'. Is this a bug ? Not really, it's a BC compatibility that we had to drag since PHP4. If you enable E_STRICT, it should output a warning saying something like "importing $this from invalid context". It is/was scheduled for cleanup in the next major version. Best, -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- Bezuz Bogdan Programare Site +40 721 269 934 bogdan.be...@emag.ro Dante International SA Tel/Fax: +40 21 200 52 00/25 Swan Office Park, Windsor Building Şos. Bucureşti Nord nr. 15-23 Bucureşti
[PHP-DEV] Unexpected behavior of $this-$propertyName[...]
Dear internals, please consider the following code executed with PHP 5.3alpha3: ?php class Foo { protected $foo = array('bar' = 'baz'); public function test() { $propertyName = 'foo'; var_dump(isset($this-foo['bar'])); var_dump(isset($this-$propertyName['bar'])); } } $object = new Foo; $object-test(); ? Expected output: array 'foo' = array 'bar' = string 'quux' (length=4) Actual output: array 'foo' = array 'bar' = string 'baz' (length=3) 'f' = string 'quux' (length=4) Is this a bug or missing feature? Cheers, robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior of $this-$propertyName[...]
On Thu, Jan 15, 2009 at 7:24 PM, Robert Lemke rob...@typo3.org wrote: Dear internals, please consider the following code executed with PHP 5.3alpha3: I suspect neither bug nor feature. I think you expect that $this-$propertyName['bar'] is the same as: ($this-$propertyName)['bar'] but in fact it is: $this-($propertyName['bar']) So in your example, 'bar' is the string index 0 for foo[0], hence 'f'. Is this a bug or missing feature? It has been pointed out before that one should be able to index an expression, but currently PHP can only index variables. Personally, it seems like a bug, but I'm not sure whether or not there's consensus. Paul -- Paul Biggar paul.big...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior of $this-$propertyName[...]
Hi Paul, Am 15.01.2009 um 20:35 schrieb Paul Biggar: I suspect neither bug nor feature. I think you expect that $this-$propertyName['bar'] is the same as: ($this-$propertyName)['bar'] but in fact it is: $this-($propertyName['bar']) So in your example, 'bar' is the string index 0 for foo[0], hence 'f'. okay, I already suspected something like that but had already suppressed that $string[0] works equally as $string{0}. It has been pointed out before that one should be able to index an expression, but currently PHP can only index variables. Personally, it seems like a bug, but I'm not sure whether or not there's consensus. IMO it feels like a bug, although I now understand the reasons. What was the reason again to deprecate curly brackets access in PHP6? It would make the situation clearer in the above example if square brackets would be deprecated instead ... Anyway, thank you for the clarification. Robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Unexpected behavior of $this-$propertyName[...]
Hello, On Thu, Jan 15, 2009 at 8:24 PM, Robert Lemke rob...@typo3.org wrote: Dear internals, please consider the following code executed with PHP 5.3alpha3: ?php class Foo { protected $foo = array('bar' = 'baz'); public function test() { $propertyName = 'foo'; var_dump(isset($this-foo['bar'])); var_dump(isset($this-$propertyName['bar'])); } } $object = new Foo; $object-test(); ? Expected output: array 'foo' = array 'bar' = string 'quux' (length=4) Actual output: array 'foo' = array 'bar' = string 'baz' (length=3) 'f' = string 'quux' (length=4) Is this a bug or missing feature? It's a simple matter of precedence. You want $this-{$propertyName}['bar']; here Regards Cheers, robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php