Re: Fechas y classes

From: Date: Wed, 13 Aug 2003 11:19:25 +0000
Subject: Re: Fechas y classes
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-39340@lists.php.net to get a copy of this message
Dimecres 13 Agost 2003 12:41, Gabi dixit: > Hola. > > Se me produce el siguiente error: > Parse error: parse error, expecting ','' or > ';'' in > /home/webcindario/gabi/fechas.php on line 4 > > Pueden verlo en: > http://gabi.webcindario.com/fechas.php > > Y tengo el siguienet codigo: > > <? > class fechas > { > var $h=date('H'); > var $minu=date('i'); > var $s=date('s'); > var $d=date('d'); Del manual de PHP (http://www.php.net/manual/en/language.oop.php): -------------------------------------- Note: In PHP 4, only constant initializers for var variables are allowed. To initialize variables with non-constant values, you need an initialization function which is called automatically when an object is being constructed from the class. Such a function is called a constructor (see below). <?php /* None of these will work in PHP 4. */ class Cart { var $todays_date = date("Y-m-d"); var $name = $firstname; var $owner = 'Fred ' . 'Jones'; var $items = array("VCR", "TV"); } /* This is how it should be done. */ class Cart { var $todays_date; var $name; var $owner; var $items; function Cart() { $this->todays_date = date("Y-m-d"); $this->name = $GLOBALS['firstname']; /* etc. . . */ } } ?> ---------------------------------------------------------- El manual en castellano está obsoleto, y no consta la anterior anotación. Es conveniente consultar SIEMPRE el manual en inglés. Saludos Àngel

« previous php.general.es (#39340) next »