|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 06:00:01 2025 UTC |
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; } }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