M. Sokolewicz wrote:

To summarize:

<?php
class Liste {

   var $input2;
   var $input;

    function Liste() { /* or, if you're using php5: public function
__construct() { */
       $this->input = array(1,2,3);
       $this->input2 = array_pad($this->input,10,1);
    }
}

The reason being, for this, that inside a class property definition, only static values are allowed. This has to do with the Static use of a class. Imagine the following (PHP 4):
--- PHP 4 ---
class foo {
var $a = 2;
var $b = 5;
}
--- end ---
or
--- PHP 5 ---
class foo {
public $a = 2;
public $b = 5;
}
--- end ---


Now, when someone uses it statically, he/she can call them like:
---
echo foo::a;

This is not entirely accurate.

<?php
class foo {
    public $a = 2;
    public $b = 5;
}
echo foo::a;

results in:

Fatal error:  Undefined class constant 'a' in PHPDocument1 on line 7

<?php
class foo {
    public $a = 2;
    public $b = 5;
}
echo foo::$a;

results in:

Fatal Error: Access to undeclared static property: foo::$a in PHPDocument1 on line 7

<?php
class foo {
    static $a = 2;
    public $b = 5;
}
echo foo::$a;

results in:

2

The reasoning behind not allowing complex expressions in variable declarations is that they must be evaluated at compile time, *before* any functions, classes, or other complex structures have been parsed and therefore created, otherwise php would be either incredibly unstable or much slower.

Greg

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to