Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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();
Note the mandatory pair of parenthesis.
In previous versions, you have to call the method on a variable:
$purchaseFactory = new PurchaseOrderFactory;
$purchaseOrder = $purchaseFactory->instance();
$purchaseOrder = PurchaseOrderFactory::instance();
$arrOrderDetails = $purchaseOrder->load($customerName);
where presumably instance()
creates an instance of the class. You can do this rather than saying new
// 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();