|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: daniel dot oconnor at gmail dot com
New email:
PHP Version: OS:


 [2006-08-07 02:19 UTC] daniel dot oconnor at gmail dot com
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-07 08:09 UTC]
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-2023 The PHP Group
All rights reserved.
Last updated: Tue Nov 28 22:01:30 2023 UTC