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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Mar 28 11:01:27 2024 UTC