|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9414 date() returns error when included in an object
Submitted: 2001-02-22 18:47 UTC Modified: 2001-02-22 19:45 UTC
From: eric at lcb dot uoregon dot edu Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.0.4pl1 OS: RedHat 6.2 i686 Apache 1.3.17
Private report: No CVE-ID: None
 [2001-02-22 18:47 UTC] eric at lcb dot uoregon dot edu
When I try to use the date() inside of a class in 
PHP4.0.4pl1 an error gets returned. 



class showDate {

var $dateTest = date("Y-m-d");


$object1 = new showDate;

echo $object1->dateTest;


Returns the following error:

Parse error: parse error, expecting `','' or `';'' in 
/path/to/file/date_test.php on line 7

My php.ini has expose tags =  off, and an include path, 
otherwise it's pretty much out of the box php.ini

I did a static build with the following config:
./configure --with-apache=../apache 
--with-mysql=/path/to/mysql --with-openssl=/path/to/ssl 
--with-zlib --with-xml --enable-bcmath



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 19:03 UTC]
Not a bug; from the manual (

 Note: In PHP 4, only constant initializers for var variables are allowed. Use 
 constructors for non-constant initializers. 

So you could have 'var $dateTest = "foo";', or 'var $dateTest = 201029;', but not
anything which would depend upon runtime evaluation.

What this means is that you should have something like this instead:

class showDate {
   var $dateTest;

   function showDate() {
      $this->dateTest = date("Y-m-d");

This could probably benefit from a better example in the manual, though.



 [2001-02-22 19:45 UTC]
Fixed in CVS; I just added a small example in the note. Thanks
for the report.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Mar 31 10:04:43 2023 UTC