PHP Parse Error: Syntax Error, Unexpected T_Object_Operator

PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR

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();

Note the mandatory pair of parenthesis.

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

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

Parse error: syntax error, unexpected '- ' (T_OBJECT_OPERATOR), expecting ')' on line 59

Inside the array you want to use the => operator for pairing keys and values whereas for chaining object methods you are correctly using the -> operator

$mailer = Swift_Mailer::newInstance($transort);
$message = Swift_Message::newInstance('Web Inquiry')
->setFrom (array('email1@myemail.com' => 'Web Inquiry'))
->setTo (array('email@email.com' => 'Inquiry Recipients'))
->setBcc (array('email@email.com' => 'Inquiry BCC Recipient, respond from email@email.com.net'))
->setSubject (array('Inquiry from email.com'))
->setBody (array($data, 'text/html'));

Destructuring assignment in JavaScript

First off, var [a, b] = f() works just fine in JavaScript 1.7 - try it!

Second, you can smooth out the usage syntax slightly using with():

var array = [1,2];
with (assign(array, { var1: null, var2: null }))
{
var1; // == 1
var2; // == 2
}

Of course, this won't allow you to modify the values of existing variables, so IMHO it's a whole lot less useful than the JavaScript 1.7 feature. In code I'm writing now, I just return objects directly and reference their members - I'll wait for the 1.7 features to become more widely available.

How to fix unexpected '- ' (T_OBJECT_OPERATOR) in Laravel?

You forgot a $ here:

$this->titles = titles->all();

Change it to:

$this->titles = $titles->all();

Parse error: syntax error, unexpected T_OBJECT_OPERATOR

The - sign means subtraction. To use it in property names, you must use this syntax:

$firstName = (string) $order->{"billing-address"}->{"first-name"};
$lastName = (string) $order->{"billing-address"}->{"last-name"};

In general, it's probably better to use firstName, billingAddress, etc. as property names to avoid this. See CamelCase. In this case, however, you may have no control over the the XML input.

PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')'

your usage of format() is wrong, change:

...
':postDate' => (new DateTime())->format('Y-m-d H:i:s')

to

...
$date = new DateTime();
$formattedDate = $date->format('Y-m-d H:i:s');
....
':postDate' => $formattedDate


Related Topics



Leave a reply



Submit