FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Parse error: syntax error, unexpected T_VARIABLE
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Parse error: syntax error, unexpected T_VARIABLE [message #177321] Sat, 10 March 2012 14:57 Go to next message
Une Bvue is currently offline  Une Bvue
Messages: 30
Registered: March 2012
Karma: 0
Member
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.
Solved ? was (Parse error: syntax error, unexpected T_VARIABLE) [message #177322 is a reply to message #177321] Sat, 10 March 2012 17:05 Go to previous messageGo to next message
Une Bvue is currently offline  Une Bvue
Messages: 30
Registered: March 2012
Karma: 0
Member
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...
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177323 is a reply to message #177321] Sat, 10 March 2012 17:45 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
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.
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177324 is a reply to message #177323] Sat, 10 March 2012 18:35 Go to previous messageGo to next message
Une Bvue is currently offline  Une Bvue
Messages: 30
Registered: March 2012
Karma: 0
Member
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;

....
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177325 is a reply to message #177321] Sat, 10 March 2012 19:06 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177326 is a reply to message #177325] Sat, 10 March 2012 19:07 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177327 is a reply to message #177324] Sat, 10 March 2012 19:13 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
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.
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177328 is a reply to message #177321] Sat, 10 March 2012 21:21 Go to previous messageGo to next message
Umberto Salsi is currently offline  Umberto Salsi
Messages: 2
Registered: August 2011
Karma: 0
Junior Member
Une Bévue <unbewusstsein(at)fai(dot)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
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177329 is a reply to message #177327] Sun, 11 March 2012 07:33 Go to previous messageGo to next message
Une Bvue is currently offline  Une Bvue
Messages: 30
Registered: March 2012
Karma: 0
Member
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 !
Re: Parse error: syntax error, unexpected T_VARIABLE [message #177330 is a reply to message #177328] Sun, 11 March 2012 07:34 Go to previous message
Une Bvue is currently offline  Une Bvue
Messages: 30
Registered: March 2012
Karma: 0
Member
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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: combobox
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 09:43:48 GMT 2024

Total time taken to generate the page: 0.02379 seconds