PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR

I got this error when debugging my code:

PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR in order.php on line 72

Here is a snippet of the code (starting on line 72):

$purchaseOrder = new PurchaseOrderFactory->instance();
$arrOrderDetails = $purchaseOrder->load($customerName);

Unfortunately, it is not possible to call a method on an object just created with new before PHP 5.4.

In PHP 5.4 and later, the following can be used:

$purchaseOrder = (new PurchaseOrderFactory)->instance();

In previous versions, you have to call the method on a variable:

$purchaseFactory = new PurchaseOrderFactory;
$purchaseOrder = $purchaseFactory->instance();

Note: The later is probably even more useful/wise even after you've upgraded to PHP 5.4 because those two lines can be better separated and there is less code containing a hard-encoded classname, here the name of the factory class PurchaseOrderFactory. This will make you more fluent maintaining the code over time.

php - Parse error: syntax error, unexpected , if (!this->setDate. This line is missing a $ before this , so this is being treated as a constant, which doesn't exist so is treated as a string, which can't have -> after  But you do not have those constants defined, so PHP thinks you mean the string "address" and "name" and trying to use the T_OBJECT_OPERATOR, e.g. -> on a String doesnt work. – Gordon Jul 9 '10 at 15:40

change to as your syntax was invalid:

$purchaseOrder = PurchaseOrderFactory::instance();
$arrOrderDetails = $purchaseOrder->load($customerName);

where presumably instance() creates an instance of the class. You can do this rather than saying new

Parse error: syntax error, unexpected T_OBJECT_OPERATOR , Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /var/www/html/​…/wp-content/plugins/wp-cassify/classes/wp_cassify_utils.php on line 627. still this error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')' – M P Jul 28 '13 at 16:30 @MP, Please try again. There was another problem, you were using -> instead of => .

You can't use (it's invalid php syntax):

new PurchaseOrderFactory->instance();

You probably meant one of those:

// Initialize new object of class PurchaseOrderFactory
new PurchaseOrderFactory(); 

// Clone instance of already existing PurchaseOrderFactory
clone  PurchaseOrderFactory::instance();

// Simply use one instance
PurchaseOrderFactory::instance();

// Initialize new object and that use one of its methods
$tmp = new PurchaseOrderFactory();
$tmp->instance();

Cant get it working :(, It passes the course but i get this error. Parse error: syntax error, unexpected T_OBJECT_OPERATOR on line 34 <?php class Dog{ public $numLegs=4; public  Side note: PHPMyAdmin is a web based management software for MySQL databases. Unless you're modifying that software's code directly, your app has noting to do with it. – Magnus Eriksson Jan 15 '18 at 6:01

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR , Hi, I have this problem Parse error: syntax error, unexpected '->' (​T_OBJECT_OPERATOR). My code is: <?php require_once  The issue is on the third line: Should be: Remember your variables must be prefixed with the dollar sign. Also, when you see a Parse Error, keep in mind it may have nothing to do with the thing it tells you (the -> for example), rather it is something before that, which makes it unable to parse the statement correctly.

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\xampp\​htdocs\test\form.php on line 10 #1185. Closed. BustedSLS  Re: [SOLVED] syntax error, unexpected T_OBJECT_OPERATOR. The answer is in the previous posts. Use phpMyAdmin from your Host's Control Panel and open your database. Open jos_plugins and set the plugin System - Mootools Upgrade to 0 (unpublished) It ain't what you don't know that gets you into trouble.

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in , Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /wp-content/​plugins/maps-marker-pro/maps-marker-pro.php on line 66. PHP Parse error: syntax error, unexpected '{' in index.php on line 20 The unexpected symbol isn't always the real culprit. But the line number gives a rough idea of where to start looking.

Comments
  • Even if he used his code on PHP 5.4 that would generate a syntax error.
  • this code works for php 4.9 version. But why does this error occur?