I get this error when debugging:

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

Here is a snippet of the code:

line 72: $purchaseOrder = new PurchaseOrderFactory->instance();
$arrOrderDetails = $purchaseOrder->load($customerName);
share|improve this question
feedback

closed as too localized by mario, bensiu, tereško, air4x, SomeKittens Nov 15 '12 at 1:51

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

3 Answers

up vote 0 down vote accepted

Unfortunately, it is not possible to call a method on an object just created with new. You have to call the method on a variable:

$purchaseFactory = new PurchaseOrderFactory;
$purchaseOrder = $purchaseFactory->instance();
share|improve this answer
thank you good sir!! – user1825110 Nov 14 '12 at 23:34
feedback

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

share|improve this answer
feedback

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();
share|improve this answer
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.