PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.comp.lang.php > unexpected T_STRING, expecting T_VARIABLE
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
unexpected T_STRING, expecting T_VARIABLE

Réponse
 
LinkBack Outils de la discussion
Vieux 30/07/2007, 22h17   #1
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut unexpected T_STRING, expecting T_VARIABLE

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();
?>


  Réponse avec citation
Vieux 30/07/2007, 22h59   #2
Rik
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: unexpected T_STRING, expecting T_VARIABLE

On Mon, 30 Jul 2007 23:17:35 +0200, Jeff
<it_consultant1@hotmail.com.NOSPAM> wrote:
> public test()


public function test()

HTH,
--
Rik Wasmus
  Réponse avec citation
Vieux 30/07/2007, 23h12   #3
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: unexpected T_STRING, expecting T_VARIABLE

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



  Réponse avec citation
Vieux 30/07/2007, 23h13   #4
Rik
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: unexpected T_STRING, expecting T_VARIABLE

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
  Réponse avec citation
Vieux 30/07/2007, 23h18   #5
Rik
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: unexpected T_STRING, expecting T_VARIABLE

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h11.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11581 seconds with 13 queries