|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-11-21 00:39 UTC] derick@php.net
[2002-11-21 16:17 UTC] tim dot lokot at printsoft dot com
[2003-02-21 07:37 UTC] cynic@php.net
[2004-02-18 00:34 UTC] irchtml@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 22:00:02 2025 UTC |
The following example doesn't work, but is listed in the documentation as being valid: <?php 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.