FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[PHP] Parse error





MrBlueSky
When I use the following code:

Code:

<?php

$o = New Object();

$res = $o->some_method(0)->prop;

?>


I get an parse error:

Quote:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /file.php on line 5


Off course the code itself doesn't do anything and will result in runtime-errors. But I wonder why I get this parse-error Question

It parses correctly using PHP5, so it probably has something to do with the way the -> operator works in earlier versions of PHP. Does anybody can tell me more?
Maxus
I dont see your Object somewhere, there is nowhere a class defined calles Object
MrBlueSky
Maxus wrote:
I dont see your Object somewhere, there is nowhere a class defined calles Object


I know. The code doesn't work, but its the parse error I don't understand: the syntax yields an error. PHP4.4 won't parse this code, while PHP5 does, and I wonder why..
Esch
PHP 5's object model is a bit more rich than PHP 4's. They probably just modified the way that calls to object methods are parsed...I realize that's a little obvious, but I don't see the point in dwelling on why you're getting a particular error or not. I mean, the exact error you'll get is just implementation-dependent and will vary by build.
MrBlueSky
Oke, I've got it: PHP4 cannot dereference object returned by method, so
this:

Code:

$result = $object->method()->property;


doesn't parse in PHP4.

Rolling Eyes

Workaround:

Code:

$temp = $object->method();
$result = $temp->property;
X3 Talk
Cross compatibility is hard when you can't install newer versions of PHP yourself. Running apps such as MediaWiki proved difficult for me when I was hosting via anothher server service, but now I host my own which is good.
Related topics
PHP => Parece mais não é
PHP/Blogger error
Impossible parse error!
Trouble figuring out a parse error
Parse error: syntax error, unexpected '{' in /home/frih/publ
Php parsing error! Need help
php error ?[parse error]
Parse error - need help
PHP Parse error on form handling - New to PHP
Parse error: syntax error, unexpected T_NEW
Parse Error in PHP I can't figure out.
getting parse error when validating css
Please can anyone help with a php script error/problem?
Cannot find parse error
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.