• Advertisement
Sign in to follow this  

[web] [PHP] Unexpected T_OBJECT_OPERATOR

This topic is 3737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The minimal example below does not work:
<?php                                // 1
  function & ret()                   // 2
  {                                  // 3
    $member -> a = "Hello, world\n"; // 4
    return $member;                  // 5
  }                                  // 6
  echo ret () -> a;                  // 7
?>
When executed, it prints the following error:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' 
in /home/arkadir/test/test.php on line 7
The error is related to the '->' operator on the seventh line. What is the reason for this error? Is there a full description of the PHP4 syntax somewhere on the web that might explain why this doesn't work, and in what cases it actually works? The operator-> itself seems to be missing from the expressions and operators sections of the PHP.net documentation.

Share this post


Link to post
Share on other sites
Advertisement
It's a well-known issue. In PHP4 you couldn't use the ()-> combination. This has been fixed in version 5. AFAIK, the only workaround available is to introduce a temporary variable:
$ret = ret();
echo $ret->a;

Share this post


Link to post
Share on other sites
Thank you for your response. Do you have any idea where I could find more detailed information about this issue? In particular, I'm looking for a rule that decides whether some code using operator -> is valid or not.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Thank you for your response. Do you have any idea where I could find more detailed information about this issue? In particular, I'm looking for a rule that decides whether some code using operator -> is valid or not.

If don't have any particular links in mind, but assume there should be more information on indirection and object operators on the Zend engine website.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement