php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: eric at lcb dot uoregon dot edu
New email:
PHP Version: OS:

 

 [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. 

Example:

<?

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

Thanks,
eric





Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 19:03 UTC] torben@php.net
Not a bug; from the manual (http://www.php.net/manual/en/language.oop.php):

 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:

<?php
class showDate {
   var $dateTest;

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

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


Cheers,

Torben

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

Torben
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC