php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44313 inconsistencies in property assignation on scalar variables
Submitted: 2008-03-02 18:19 UTC Modified: 2008-08-06 03:39 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: johann dot queuniet at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.5 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: johann dot queuniet at gmail dot com
New email:
PHP Version: OS:

 

 [2008-03-02 18:19 UTC] johann dot queuniet at gmail dot com
Description:
------------
The way PHP handles property assignation on scalar variables evaluating 
as false is inconsistent.

Reproduce code:
---------------
<?php
$var1->test = true;

$var2 = null;
$var2->test = true;

$var3 = false;
$var3->test = true;

$var3 = '';
$var3->test = true;

$var4 = 0;
$var4->test = true;

$var5 = '0';
$var5->test = true;

$var6 = array();
$var6->test = true;
?>

Expected result:
----------------
PHP should handle every case the same way, with a "Warning: Attempt to 
assign property of non-object". The first line should also trigger a 
notice since the $var1 variable is undeclared.

Actual result:
--------------
PHP behaves as with arrays and only triggers a warning for the last 
three. The other lines create an stdClass object with the test property 
set.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-02 21:33 UTC] felipe@php.net
Using E_STRICT, "Strict Standards: Creating default object from empty value" are showed for other cases.
 [2008-08-06 03:39 UTC] jani@php.net
AS Felipe said, it's for BC and you do get warning with E_STRICT.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 01:01:32 2025 UTC