php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24499 Notice: Undefined property: stdClass::
Submitted: 2003-07-04 11:35 UTC Modified: 2003-07-21 07:13 UTC
From: wks at wks dot ch Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0b1 (beta1) OS: *
Private report: No CVE-ID: None
 [2003-07-04 11:35 UTC] wks at wks dot ch
Description:
------------
In a class, if 'private' is used instead of 'var' for a variable declaration then it fails with the Notice:

Undefined property: stdClassr'.

This still occurs if you make '$record = pg_fetch_object($q); return $record->id;'

Reproduce code:
---------------
<?php
class   Id
{
        private $id;
//      var     $id;
        public function getId()
        {
                $conn   = pg_connect("dbname=db user=user password=pwd");
                $q      = pg_query($conn, "SELECT id FROM id");
                $id     = pg_fetch_object($q);
                return $id->id;
        }
}
$id = new Id();
echo $id->getId();
?>

Expected result:
----------------
1

Actual result:
--------------
Notice: Undefined property: stdClass::$id in /path/id_test.php on line 11

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-05 06:26 UTC] helly@php.net
Make it a doc problem since you obviously didn't read the docs. And close it since it's all your fault :-)

What you're missing....

class {
  private $id;
  function getId() {
    $this->id = 1;
    return $this->id;
  }
}
 [2003-07-05 07:25 UTC] wks at wks dot ch
There's unfortunately been added a note by someone who hasn't understood the problem at all.

$this->id is a private variable of the class Id
$id-id is a propertie of a PostgreSQL object

php 5.0.0b1 is unable to derive the $id->id property of the $id PostgreSQL object !
 [2003-07-10 08:53 UTC] wks at wks dot ch
I've just changed the status from documentation to crash 'cause that's what it does. In more details:

$this->id is a private variable of the class Id
$id->id is a propertie of a PostgreSQL object

php 5.0.0b1 is unable to dereference the $id->id property of the $id PostgreSQL object !
 [2003-07-20 12:18 UTC] helly@php.net
This affects more than ext/pgsql. some internal facility is wrong it seems.
 [2003-07-21 07:13 UTC] zeev@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2004-07-28 23:07 UTC] jmaguire123 at hotmail dot com
I tried the latest CVS snapshot (php5-200407281830.tar.gz)as recommened above but it did not fix my issue.

I am still seeing:

Undefined property: stdClass::$id 
Undefined property: stdClass::$name

(Using PEAR::DB) with mysql on the back end, here is what I am trying to do:

$stmt = "SELECT * FROM " . CUSTOMER_TABLE;
$result = $conn->query($stmt);

while ($customer = (object) $result->fetchRow() ) {

        if ($customer->id == $params['cid']) {

                $t->set_var("CID_SELECTED", " selected");

        } else {

                $t->set_var("CID_SELECTED", "");
        }

        $t->set_var("CUSTOMER_ID", $customer->id);
        $t->set_var("CUSTOMER_NAME", $customer->name);

}
etc..


All of the above code worked fine in PHP 4.3.7 (and still does--I checked).

Broken in PHP 5 (and page goes into an infinate loop of notices) Any help is greatly appreciated.. Suggest re-opening this bug report.

-John
 [2004-07-29 02:44 UTC] jmaguire123 at hotmail dot com
After I removed "(object)" from the while loop, everything started working again.

Must be my mistake.  I guess one does not need to do that anymore.

-John
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC