|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49348 Uninitialized ++$foo->bar; does not cause a notice (but ++$bar; does!)
Submitted: 2009-08-24 16:21 UTC Modified: 2013-02-20 08:35 UTC
Avg. Score:3.2 ± 1.1
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: BelStudent at yandex dot ru Assigned: stas (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
24 + 40 = ?
Subscribe to this entry?

 [2009-08-24 16:21 UTC] BelStudent at yandex dot ru
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:
class A
{ public function __construct()
    {   ++$this->num;
new A();

Expected result:
Undefined property:  A::$num

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-25 07:13 UTC]
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:

That the code described by this bug doesn't is an inconsistency.
 [2009-08-25 08:18 UTC]
Reopened, Gwynne's arguments are rock solid. :)
 [2009-08-27 21:06 UTC]
In _get_zval_cv_lookup(), type is BP_VAR_W, while it should be BP_VAR_RW for the example code.
 [2009-08-31 22:12 UTC]
# 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-09-01 08:41 UTC]
I was talking about this:

With ++$foo, type is BP_VAR_RW, which makes sense and gives a notice. With ++$this->foo, it is BP_VAR_W.
 [2013-02-19 04:59 UTC]
The problem here is that get_property_ptr_ptr does not produce notices. It doesn't 
because it does not know the fetch type - in some cases it's BP_VAR_W, then it 
shouldn't produce notice, in some it's BP_VAR_RW and then it should. However 
get_property_ptr_ptr doesn't have a parameter to pass this info.

Looks like such parameter needs to be added...
 [2013-02-19 09:18 UTC]
Potential fix in this pull:
 [2013-02-20 08:35 UTC]
I think the fix is fine, but it may go only into 5.5 and above.
 [2013-02-21 08:58 UTC]
Automatic comment on behalf of stas
Log: fix bug #49348 - issue notice on get_property_ptr_ptr when used for read
 [2013-02-21 08:58 UTC]
-Status: Assigned +Status: Closed
 [2013-03-29 20:07 UTC] bugs dot php dot net at majkl578 dot cz
The message is not consistent with the other one triggered in similar case.

Consider the following code:
$x = new stdClass();
echo $x->foo++;
echo $x->bar;

It triggers two notices:
Notice: Undefined property: foo
Notice: Undefined property: stdClass::$bar

The first one was added by fix for this bug and is wrong. It should be same as the other one (should contain classname and dollar).
 [2013-11-17 09:31 UTC]
Automatic comment on behalf of stas
Log: fix bug #49348 - issue notice on get_property_ptr_ptr when used for read
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 12:01:31 2024 UTC