#38362 [Opn->Bgs]: "Fatal error: Cannot access empty property" unexpectedly

From: Date: Mon, 07 Aug 2006 08:09:04 +0000
Subject: #38362 [Opn->Bgs]: "Fatal error: Cannot access empty property" unexpectedly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100445@lists.php.net to get a copy of this message
ID: 38362 Updated by: tony2001@php.net Reported By: daniel dot oconnor at gmail dot com -Status: Open +Status: Bogus Bug Type: *General Issues PHP Version: 5.1.4 New Comment: var_dump($$date); -> NULL $$date means "the variable, which names is in $date". Since there are no such variables as $date_Created, $appointment_Date etc., the error is correct. Change $$ to $. Previous Comments: ------------------------------------------------------------------------ [2006-08-07 02:19:02] daniel dot oconnor at gmail dot com Description: ------------ See also: 28444 PHP gives unexpected errors when creating an object. I understand that i'm constructing an object, and some properties aren't there yet for reading; but I would have expected $this->$$date to work exactly the same as $this->date_Created... I would also have thought that declaring the class with a value in the protected member vars meant that these variables are not empty! Reproduce code: --------------- class NexusJob { protected $date_Created = ''; //dateTime protected $appointment_Date = ''; //dateTime protected $valuation_Date = ''; //dateTime protected $inspection_Date = ''; //dateTime public function __construct() { $dates = array('date_Created', 'appointment_Date', 'valuation_Date', 'inspection_Date'); foreach ($dates as $date) { $this->$$date = date(DATE_W3C); } } } $nj = new NexusJob(); Expected result: ---------------- No errors Actual result: -------------- Fatal error: Cannot access empty property ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38362&edit=1

« previous php.bugs (#100445) next »