php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38362 "Fatal error: Cannot access empty property" unexpectedly
Submitted: 2006-08-07 02:19 UTC Modified: 2006-08-07 08:09 UTC
From: daniel dot oconnor at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.1.4 OS:
Private report: No CVE-ID: None
 [2006-08-07 02:19 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-07 08:09 UTC] tony2001@php.net
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 $. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC