|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
PHP 5.2.3
When I execute this code I get an "unexpected T_STRING, expecting T_VARIABLE" error .. on line 13, which is this line : public test() If I comment out this test method and execute this script then only ****************************************** is displayed. I thought it at least should display the "constructing A" and "constructing B" any suggestions? below is the problem code: ************* the code ************ <?php class A { public $name; public function __constructor() { echo "constructing A"; $this->$name = "helloworld"; } public test() { return 4; } public function __get($name) { return $name; } } class B extends A { public function __constructor() { parent::__constructor(); echo "constructing B"; } } echo "******************************************"; $noob = new B(); echo $noob->test(); ?> |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Mon, 30 Jul 2007 23:17:35 +0200, Jeff
<it_consultant1@hotmail.com.NOSPAM> wrote: > public test() public function test() HTH, -- Rik Wasmus |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
thanks,
BTW why isn't any text displayed on the page (it only displays ******************)? is echo allowed in constructor? "Rik" <luiheidsgoeroe@hotmail.com> wrote in message news p.twasp4ejqnv3q9@metallium...> On Mon, 30 Jul 2007 23:17:35 +0200, Jeff > <it_consultant1@hotmail.com.NOSPAM> wrote: >> public test() > > public function test() > > HTH, > -- > Rik Wasmus |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Mon, 30 Jul 2007 23:59:54 +0200, Rik <luiheidsgoeroe@hotmail.com> wrote:
> On Mon, 30 Jul 2007 23:17:35 +0200, Jeff > <it_consultant1@hotmail.com.NOSPAM> wrote: >> public test() > > public function test() > > HTH, Oh, and about the 'cryptic' message: 'public', not followed by 'function' (with possbile keyword in between like 'static') is assumed to be a property of the class, so it has to start with $. The parser didn't even come to point where it could realise you tried to create a method: it saw a 'naked' string, hence the 'expected var but got a string'. -- Rik Wasmus |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Tue, 31 Jul 2007 00:12:38 +0200, Jeff
<it_consultant1@hotmail.com.NOSPAM> wrote: > thanks, > > BTW why isn't any text displayed on the page (it only displays > ******************)? is echo allowed in constructor? It sure is, but this was a parse error: in building the actual low-level representation of the script PHP could not figure out what something meant, so nothing in your script gets run, not a thing. Only after valid PHP syntax is parsed it will run, with possible run time errors it only then encounters, in which case anything up to that error is run (for instance an undefined function: your function can be declared anywhere in the script, which may or may not include files, but PHP does not check this prior to running, because it simply doesn't know, and function names can even be set at runtime with possible create_function() statements etc.). -- Rik Wasmus |
|
![]() |
| Outils de la discussion | |
|
|