Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5138 > unrolled thread

Parse error: syntax error, unexpected T_VARIABLE

Started byUne Bévue <unbewusstsein@fai.invalid>
First post2012-03-10 15:57 +0100
Last post2012-03-11 08:34 +0100
Articles 10 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  Parse error: syntax error, unexpected T_VARIABLE Une Bévue <unbewusstsein@fai.invalid> - 2012-03-10 15:57 +0100
    Solved ? was (Parse error: syntax error, unexpected T_VARIABLE) Une Bévue <unbewusstsein@fai.invalid> - 2012-03-10 18:05 +0100
    Re: Parse error: syntax error, unexpected T_VARIABLE "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-10 18:45 +0100
      Re: Parse error: syntax error, unexpected T_VARIABLE Une Bévue <unbewusstsein@fai.invalid> - 2012-03-10 19:35 +0100
        Re: Parse error: syntax error, unexpected T_VARIABLE "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-10 20:13 +0100
          Re: Parse error: syntax error, unexpected T_VARIABLE Une Bévue <unbewusstsein@fai.invalid> - 2012-03-11 08:33 +0100
    Re: Parse error: syntax error, unexpected T_VARIABLE Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-10 14:06 -0500
      Re: Parse error: syntax error, unexpected T_VARIABLE Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-10 14:07 -0500
    Re: Parse error: syntax error, unexpected T_VARIABLE Umberto Salsi <salsi@icosaedro.italia> - 2012-03-10 22:21 +0100
      Re: Parse error: syntax error, unexpected T_VARIABLE Une Bévue <unbewusstsein@fai.invalid> - 2012-03-11 08:34 +0100

#5138 — Parse error: syntax error, unexpected T_VARIABLE

FromUne Bévue <unbewusstsein@fai.invalid>
Date2012-03-10 15:57 +0100
SubjectParse error: syntax error, unexpected T_VARIABLE
Message-ID<4f5b6bf3$0$1970$426a34cc@news.free.fr>
at line :
public static $JAR=$_SERVER['DOCUMENT_ROOT'] . 
'/AB2Html/Builder/saxon9he.jar';

i got the error :
Parse error: syntax error, unexpected T_VARIABLE

this is inside a class.

if i test the above line apart, in another script, outside any class, i 
get NO error.

then, is that forbiden using such a variable "$_SERVER['DOCUMENT_ROOT'" 
inside a class ?

the purpose of using it is to allow my script working on both ubuntu and 
Mac OS X.

[toc] | [next] | [standalone]


#5139 — Solved ? was (Parse error: syntax error, unexpected T_VARIABLE)

FromUne Bévue <unbewusstsein@fai.invalid>
Date2012-03-10 18:05 +0100
SubjectSolved ? was (Parse error: syntax error, unexpected T_VARIABLE)
Message-ID<4f5b89f3$0$1751$426a34cc@news.free.fr>
In reply to#5138
Le 10/03/2012 15:57, Une Bévue a écrit :
> at line :
> public static $JAR=$_SERVER['DOCUMENT_ROOT'] .
> '/AB2Html/Builder/saxon9he.jar';
>
> i got the error :
> Parse error: syntax error, unexpected T_VARIABLE
>
> this is inside a class.
>
> if i test the above line apart, in another script, outside any class, i
> get NO error.
>
> then, is that forbiden using such a variable "$_SERVER['DOCUMENT_ROOT'"
> inside a class ?
>
> the purpose of using it is to allow my script working on both ubuntu and
> Mac OS X.

i put those vars outside of the class like this :
define('JAVA_BIN', '/usr/bin/java');
define('SAXON9HE_JAR', $_SERVER['DOCUMENT_ROOT'] . 
'/AB2Html/Builder/saxon9he.jar');

class XSLTSaxonProcessor {

and that works fine...

[toc] | [prev] | [next] | [standalone]


#5140

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-03-10 18:45 +0100
Message-ID<9s1ia6FmqdU1@mid.uni-berlin.de>
In reply to#5138
Am 10.03.2012 15:57, schrieb Une Bévue:
> at line :
> public static $JAR=$_SERVER['DOCUMENT_ROOT'] . '/AB2Html/Builder/saxon9he.jar';
> 
> i got the error :
> Parse error: syntax error, unexpected T_VARIABLE
> 
> this is inside a class.
> 
> if i test the above line apart, in another script, outside any class, i get NO error.
> 
> then, is that forbiden using such a variable "$_SERVER['DOCUMENT_ROOT'" inside a class ?
> 
> the purpose of using it is to allow my script working on both ubuntu and Mac OS X.

missing semicolon? in the line before.


/Str.

[toc] | [prev] | [next] | [standalone]


#5141

FromUne Bévue <unbewusstsein@fai.invalid>
Date2012-03-10 19:35 +0100
Message-ID<4f5b9ef5$0$8623$426a74cc@news.free.fr>
In reply to#5140
Le 10/03/2012 18:45, M. Strobel a écrit :
> missing semicolon? in the line before.

no, I did verify this point.

in fact i comment out the faulty line and put after it :

public static $JAR='/home/yt/Sites/AB2Html/Builder/saxon9he.jar';
surprisingly the part giving the error, was,for me :
$_SERVER['DOCUMENT_ROOT']

in a class :

<?php

define('JAVA_BIN', '/usr/bin/java');
define('SAXON9HE_JAR', $_SERVER['DOCUMENT_ROOT'] . 
'/AB2Html/Builder/saxon9he.jar');

class XSLTSaxonProcessor {
	//public static $JAVA='/usr/bin/java';
	//public static $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
	//$JAR=$_SERVER['DOCUMENT_ROOT'] . '/AB2Html/Builder/saxon9he.jar';
	// Parse error: syntax error, unexpected T_VARIABLE in 
/home/yt/Sites/AB2Html/Builder/xsltsaxonproc.php on line 5
	//public static $JAR='/home/yt/Sites/AB2Html/Builder/saxon9he.jar';
	public static $xsl;
	public static $xml;
	public static $params;
	public static $out;

...

[toc] | [prev] | [next] | [standalone]


#5144

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2012-03-10 20:13 +0100
Message-ID<9s1nekF1bjU1@mid.uni-berlin.de>
In reply to#5141
Am 10.03.2012 19:35, schrieb Une Bévue:
> Le 10/03/2012 18:45, M. Strobel a écrit :
>> missing semicolon? in the line before.
> 
> no, I did verify this point.
> 
> in fact i comment out the faulty line and put after it :
> 
> public static $JAR='/home/yt/Sites/AB2Html/Builder/saxon9he.jar';
> surprisingly the part giving the error, was,for me :
> $_SERVER['DOCUMENT_ROOT']
> 
> in a class :
> 
> <?php
> 
> define('JAVA_BIN', '/usr/bin/java');
> define('SAXON9HE_JAR', $_SERVER['DOCUMENT_ROOT'] . '/AB2Html/Builder/saxon9he.jar');
> 
> class XSLTSaxonProcessor {
>     //public static $JAVA='/usr/bin/java';
>     //public static $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
>     //$JAR=$_SERVER['DOCUMENT_ROOT'] . '/AB2Html/Builder/saxon9he.jar';
this is the offending line
>     // Parse error: syntax error, unexpected T_VARIABLE in
> /home/yt/Sites/AB2Html/Builder/xsltsaxonproc.php on line 5
>     //public static $JAR='/home/yt/Sites/AB2Html/Builder/saxon9he.jar';
>     public static $xsl;
>     public static $xml;
>     public static $params;
>     public static $out;
> 
> ...
> 

Okay, I can see the error. I suppose it is a limitation of the direct variable
initialization, but I could not find any reference about it.

Put your init code in the constructor in this case.

/Str.

[toc] | [prev] | [next] | [standalone]


#5146

FromUne Bévue <unbewusstsein@fai.invalid>
Date2012-03-11 08:33 +0100
Message-ID<4f5c5532$0$13206$426a74cc@news.free.fr>
In reply to#5144
Le 10/03/2012 20:13, M. Strobel a écrit :
> Okay, I can see the error. I suppose it is a limitation of the direct variable
> initialization, but I could not find any reference about it.
>
> Put your init code in the constructor in this case.

ok thanks, i'll try that !

[toc] | [prev] | [next] | [standalone]


#5142

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-03-10 14:06 -0500
Message-ID<jjg8ob$n4f$2@dont-email.me>
In reply to#5138
On 3/10/2012 9:57 AM, Une Bévue wrote:
> at line :
> public static $JAR=$_SERVER['DOCUMENT_ROOT'] .
> '/AB2Html/Builder/saxon9he.jar';
>
> i got the error :
> Parse error: syntax error, unexpected T_VARIABLE
>
> this is inside a class.
>
> if i test the above line apart, in another script, outside any class, i
> get NO error.
>
> then, is that forbiden using such a variable "$_SERVER['DOCUMENT_ROOT'"
> inside a class ?
>
> the purpose of using it is to allow my script working on both ubuntu and
> Mac OS X.

You can only initialize a static to a literal.  This is not a literal.

You can do it - you just need to do it in the constructor.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5143

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-03-10 14:07 -0500
Message-ID<jjg8pi$n4f$3@dont-email.me>
In reply to#5142
On 3/10/2012 2:06 PM, Jerry Stuckle wrote:
> On 3/10/2012 9:57 AM, Une Bévue wrote:
>> at line :
>> public static $JAR=$_SERVER['DOCUMENT_ROOT'] .
>> '/AB2Html/Builder/saxon9he.jar';
>>
>> i got the error :
>> Parse error: syntax error, unexpected T_VARIABLE
>>
>> this is inside a class.
>>
>> if i test the above line apart, in another script, outside any class, i
>> get NO error.
>>
>> then, is that forbiden using such a variable "$_SERVER['DOCUMENT_ROOT'"
>> inside a class ?
>>
>> the purpose of using it is to allow my script working on both ubuntu and
>> Mac OS X.
>
> You can only initialize a static to a literal. This is not a literal.
>
> You can do it - you just need to do it in the constructor.
>

I should say a literal or other constant.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5145

FromUmberto Salsi <salsi@icosaedro.italia>
Date2012-03-10 22:21 +0100
Message-ID<jjggl6$uld$1@nnrp.ngi.it>
In reply to#5138
Une Bévue <unbewusstsein@fai.invalid> wrote:

> at line :
> public static $JAR=$_SERVER['DOCUMENT_ROOT'] . 
> '/AB2Html/Builder/saxon9he.jar';
> 
> i got the error :
> Parse error: syntax error, unexpected T_VARIABLE

The expression giving the initial value of a proprty must be statically
evaluable and must result to be NULL, FALSE, TRUE, int numbers and simple
operations with int (+ - * / % << >>), float numbers and simple operations with
float (+ - * /), string and string concatenation, other named constants
statically evaluable, or array() with keys and values that are static
expressions as well. Functions and variables like $_SERVER are not allowed
because can be evaluated only at runtime. This same limitation of the PHP
interpreter holds also for: class constants; function default values.

The official manual (http://www.php.net/manual/en/language.oop5.properties.php)
only states:

"This declaration may include an initialization, but this initialization must
be a constant value--that is, it must be able to be evaluated at compile time
and must not depend on run-time information in order to be evaluated."

but now you know the full story.

Regards,
 ___ 
/_|_\  Umberto Salsi
\/_\/  www.icosaedro.it

[toc] | [prev] | [next] | [standalone]


#5147

FromUne Bévue <unbewusstsein@fai.invalid>
Date2012-03-11 08:34 +0100
Message-ID<4f5c5597$0$13206$426a74cc@news.free.fr>
In reply to#5145
Le 10/03/2012 22:21, Umberto Salsi a écrit :
> The expression giving the initial value of a proprty must be statically
> evaluable and must result to be NULL, FALSE, TRUE, int numbers and simple
> operations with int (+ - * / %<<  >>), float numbers and simple operations with
> float (+ - * /), string and string concatenation, other named constants
> statically evaluable, or array() with keys and values that are static
> expressions as well. Functions and variables like $_SERVER are not allowed
> because can be evaluated only at runtime. This same limitation of the PHP
> interpreter holds also for: class constants; function default values.
>
> The official manual (http://www.php.net/manual/en/language.oop5.properties.php)
> only states:
>
> "This declaration may include an initialization, but this initialization must
> be a constant value--that is, it must be able to be evaluated at compile time
> and must not depend on run-time information in order to be evaluated."
>
> but now you know the full story.


ok fine, cristall clear ! thanks.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web