#49348 [Asn]: Uninitialized ++$foo->bar; does not cause a notice (but ++$bar; does!)
| From: | sjoerd@php.net | Date: | Tue, 01 Sep 2009 08:41:52 +0000 |
| Subject: | #49348 [Asn]: Uninitialized ++$foo->bar; does not cause a notice (but ++$bar; does!) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-141786@lists.php.net to get a copy of this message | ||
ID: 49348
Updated by: sjoerd@php.net
Reported By: BelStudent at yandex dot ru
Status: Assigned
Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5.*, 6
Assigned To: stas
New Comment:
I was talking about this:
http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_execute.c?revision=286362&view=markup#l251
With ++$foo, type is BP_VAR_RW, which makes sense and gives a notice.
With ++$this->foo, it is BP_VAR_W.
Previous Comments:
------------------------------------------------------------------------
[2009-08-31 22:12:10] jani@php.net
# svn log -r100312 zend_object_handlers.c
------------------------------------------------------------------------
r100312 | stas | 2002-10-20 22:22:04 +0300 (Sun, 20 Oct 2002) | 2
lines
looks like this message should go
---
Stas, care to explain? Uncommenting that will bring back the notice.
And Sjoerd, what did you mean with that comment..?
------------------------------------------------------------------------
[2009-08-27 21:06:36] sjoerd@php.net
In _get_zval_cv_lookup(), type is BP_VAR_W, while it should be
BP_VAR_RW for the example code.
------------------------------------------------------------------------
[2009-08-25 08:18:09] jani@php.net
Reopened, Gwynne's arguments are rock solid. :)
------------------------------------------------------------------------
[2009-08-25 07:13:46] gwynne@php.net
Actually, this is a valid problem; the problem described by bug #21008
is a different issue. There seems to be some confusion as to whether it
should be fixed or not, but it's neither a duplicate nor bogus.
Specifically, bug #21008 describes an issue with setting a variable to
a value, where this report describes an issue with updating a variable.
These are two distinct operations, and are handled differently.
More to the point, the following code throws a notice:
<?php
++$n;
?>
That the code described by this bug doesn't is an inconsistency.
------------------------------------------------------------------------
[2009-08-24 16:21:58] BelStudent at yandex dot ru
Description:
------------
Usually, if you try to do this: ++$num, then thrown notice, that the
"Undefined variable: num". This helps avoid errors.
But if you have class and you're trying to do so ++$this->num num
nowhere and had not previously identified, then the issue no warnings
and notices.
Accidentally deleted in the symbol and received ++$this->nu, and then
climbed into hell knows what mistakes to find this place and correct to
++$this->num took several hours. So I am very concerned about the issue:
how to do so were given notice, if you try to do something with
uninitialized (unknown) variable in the class?
Reproduce code:
---------------
<?php
class A
{ public function __construct()
{ ++$this->num;
}
}
new A();
?>
Expected result:
----------------
Undefined property: A::$num
Actual result:
--------------
empty
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49348&edit=1