|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #20531 Object property association broken
Submitted: 2002-11-20 21:50 UTC Modified: 2004-02-18 00:34 UTC
Avg. Score:3.5 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: tim dot lokot at printsoft dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.3 OS: Win NT 4 Server
Private report: No CVE-ID: None
 [2002-11-20 21:50 UTC] tim dot lokot at printsoft dot com
The following example doesn't work, but is listed in the documentation as being valid:

class DateTime {
  function DateTime() {
      // empty constructor

  function now() {
      return date("Y-m-d H:i:s");

class Report {
  var $_dt = new DateTime();
  // more properties ...

  function Report() {
      // initialization code ...

  function generateReport() {
      $dateTime = $_dt->now();
      // more code ...

  // more methods ...

$rep = new Report(); 

This returns the error:

Parse error: parse error, unexpected T_NEW in test.php on line 14

I have tried this with other classes and basically it seems that you cannot default a class property to an instatiated class unless through the constructor.  This is contrary to the documentation.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-21 00:39 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Read the note under the caution block:
 [2002-11-21 16:17 UTC] tim dot lokot at printsoft dot com
Fair enough, the docs at the url you supplied then contradict the docs at this url:

You will find that the example I supplied came direct from your online manual.

I know it says its experimental, but I thought we were supposed to report these types of inconsistencies and errors so that the experimental extensions can move to stable versions.
 [2003-02-21 07:37 UTC]
this is a docuprob, as the aggregate page has an example that's illegal in PHP.
 [2004-02-18 00:34 UTC]
This bug was fixed with revision 1.10 of objaggregation/reference.xml on 12/11/2003.

Status -> Closed
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 06:03:45 2022 UTC