php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31715 isset() and empty() return "Trying to get property of non-object"
Submitted: 2005-01-27 05:38 UTC Modified: 2010-07-13 14:06 UTC
Votes:7
Avg. Score:3.3 ± 1.2
Reproduced:5 of 6 (83.3%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: cryptographite at comcast dot net Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.3 OS: FreeBSD
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: cryptographite at comcast dot net
New email:
PHP Version: OS:

 

 [2005-01-27 05:38 UTC] cryptographite at comcast dot net
Description:
------------
Using isset() or empty() on an unset child/parent object throws "Trying to get property of non-object" errors.

This is contrary to the behavior of PHP 4 and makes no sense given the purpose of the functions and their descriptions.

isset() and empty() should properly handle querying unset objects for children without returning errors.

Reproduce code:
---------------
<?php
echo '$not->set->variable' . "\n";
echo isset($not->set->variable) ? 'isset true' : 'isset false';
echo "\n";
echo empty($not->set->variable) ? 'empty true' : 'isset false';
echo "\n------------------\n";

echo '$not->set[$key]' . "\n";
echo isset($not->set[$key]) ? 'isset true' : 'isset false';
echo "\n";
echo empty($not->set[$key]) ? 'empty true' : 'empty false';
echo "\n";
?>

Expected result:
----------------
Expected output:  (No error messages)

$not->set->variable
isset false
empty true
------------------
$not->set[$key]
isset false
empty true


Actual result:
--------------
$not->set->variable
PHP Notice:  Trying to get property of non-object in - on line 3

Notice: Trying to get property of non-object in - on line 3
isset false
PHP Notice:  Trying to get property of non-object in - on line 5

Notice: Trying to get property of non-object in - on line 5
empty true
------------------
$not->set[$key]
PHP Notice:  Undefined variable:  key in - on line 9

Notice: Undefined variable:  key in - on line 9
PHP Notice:  Trying to get property of non-object in - on line 9

Notice: Trying to get property of non-object in - on line 9
isset false
PHP Notice:  Undefined variable:  key in - on line 11

Notice: Undefined variable:  key in - on line 11
PHP Notice:  Trying to get property of non-object in - on line 11

Notice: Trying to get property of non-object in - on line 11
empty true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-27 08:12 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip
 [2005-02-04 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-01-08 10:12 UTC] ninuhadida at gmail dot com
I am experiencing the same problem with PHP 5.1.2 on SUSE Linux
 [2010-01-08 11:07 UTC] aharvey@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

5.1.2 is an extremely old version of PHP. Please try again with a current version.

FWIW, I can't reproduce this with 5.2.10-whatever-Ubuntu-ship or 5.3.1 -- the only notices are to do with the use of the undefined $key variable as an array index, which are valid. The expected output is:

$not->set->variable
isset false
empty true
------------------
$not->set[$key]

Notice: Undefined variable: key in /tmp/test.php on line 11
isset false

Notice: Undefined variable: key in /tmp/test.php on line 13
empty true

 [2010-01-16 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-06-22 00:37 UTC] felipe@php.net
-Status: No Feedback +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-07-13 14:03 UTC] info at steffisgarten dot de
I'm experiencing the same problem using php 5.3.2 under Ubuntu Lucid (5.3.2-1ubuntu4.2).
This is really annoying since the isset() function is supposed to check whether the object exists or not, so the error makes so sense for me.
 [2010-08-05 19:55 UTC] non at dot dot com
It's very confusing. I get ... on non-object ... error, too.
Im Using Ubuntu and it seems that ubuntu automaticly uses the suhosin plugin.
Maybe the error is in this part of software.
The Object will be returned correctly.
My Object is of type Zend_Db_Table_Row_Abstract.
If i use var_dump($obj->text); it will return the text.
If i use gettype($obj) it will return the class name.
But if i try to use this in the view script i receive this confusing error.
No solution =/
 [2010-08-05 20:19 UTC] php at 28-n-half dot de
For example: (in view script)

<?php

    $obj = $this->{$index.'_heading1'};
    $text = $obj->text;
    var_dump($text);

?>

ends in an error ... on non-object ...

<?php

   $obj = $this->{$index.'_heading1'};
   $text = $obj->text;
   die(var_dump($text));

?>

returns the right string

... this can't be a fail on me =/ ...

All objects will be loaded correctly.
But if i try to access the object property it fails.
Please Email me on solution, i stucking in this problem.
Thanks in Advance
 [2010-08-05 20:49 UTC] php at 28-n-half dot de
Ok, it was my fault. In my ZF View Helper I've used wrong conditions.
Never the less, mistery behaviour - i think on parsing side the object was missed.
Sorry for the wrong alarm ;)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 22 05:00:03 2025 UTC