php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44660 Indexed and reference assignment to propery of non-object don't trigger warning
Submitted: 2008-04-07 13:22 UTC Modified: 2008-07-26 18:00 UTC
From: robin_fernandes at uk dot ibm dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3CVS-2008-04-07 (snap) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: robin_fernandes at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2008-04-07 13:22 UTC] robin_fernandes at uk dot ibm dot com
Description:
------------
Attempting to read or write to a property of a (non-empty) non-object usually results in a notice or a warning.

However, no warning or notice is raised when performing an indexed or reference assignment. Consequently, the assignment fails silently. 

Confirmed on 5_2, 5_3 and HEAD snaps.

Reproduce code:
---------------
<?php
$s = "hello";
$a = true;

echo "--> read access: ";
echo $a->p;

echo "\n--> direct assignment: ";
$a->p = $s;

echo "\n--> increment: ";
$a->p++;

echo "\n--> reference assignment:";
$a->p =& $s;

echo "\n--> indexed assignment:";
$a->p[0] = $s;

echo "\n\n\n--> Confirm assignments have had no impact:";
var_dump($a, $a->p);
?>

Expected result:
----------------
--> read access: 
Notice: Trying to get property of non-object in %s on line 6

--> direct assignment: 
Warning: Attempt to assign property of non-object in %s on line 9

--> increment: 
Warning: Attempt to increment/decrement property of non-object in %s on line 12

--> reference assignment:
--> indexed assignment:


--> Confirm assignments have had no impact:
Notice: Trying to get property of non-object in %s on line 21
bool(true)
NULL
 

Actual result:
--------------
--> read access: 
Notice: Trying to get property of non-object in %s on line 6

--> direct assignment: 
Warning: Attempt to assign property of non-object in %s on line 9

--> increment: 
Warning: Attempt to increment/decrement property of non-object in %s on line 12

--> reference assignment:
Warning: Attempt to assign property of non-object in %s on line 15

--> indexed assignment:
Warning: Attempt to assign property of non-object in %s on line 18



--> Confirm assignments have had no impact:
Notice: Trying to get property of non-object in %s on line 21
bool(true)
NULL
 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-07 13:24 UTC] robin_fernandes at uk dot ibm dot com
Expected & actual result should be the other way around: the warnings for reference and indexed assignments are currently missing.
Sorry!
 [2008-07-21 12:15 UTC] pajoye@php.net
Not Os specific. Bug still present in 5.3/HEAD.


 [2008-07-26 18:00 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_3.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC