Syntax error unexpected t_object_operator

New Page

mrobot21

MrRobot21 OP

Posted 5 years ago

syntax error, unexpected ‘->’ (T_OBJECT_OPERATOR), expecting ‘]’

hello nice people

I was taking the Laracast API course

I get the following error

Copy the FatalErrorException code in LessonsController.php line 19: syntax error, ‘->’ unexpected (T_OBJECT_OPERATOR), expect ‘]’

my controller is

Copy the code <?php namespace App\Http\Controllers; use App\lesson; use Response; use Illuminate\Http\Request; class LessonsController extend Controller { //get everything and pass ‘data’ metadata public function index() { $lessons = Lesson::all(); return Response ::json([ ‘data’ => this->transform($lessons) ], 200); } //get by id public function show($id) { $lesson = Lesson::find($id); if(! $lesson) { return Response::json([ ‘error’ => [ ‘message’ => ‘No response, please try again’ ] ], 404); } return Response::json([ ‘data’ => $lesson->toArray() ], 200); } //transform lessons data and return only required fields public function transform($lessons) { return array_map(function($lesson) { return [ ‘title’ => $lesson[‘title’], ‘body’ => $lesson[‘body’], ‘avtive’ => $lesson[‘completed’], ]; }, $lessons->toArray()); } }

Thanks

PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR

Ask

Asked 9 years, 10 months ago

Modified 1 year, 11 months ago

viewed 100k times

Report this ad

This question shows research effort; it is useful and clear

52

This question shows no research effort; it’s not clear or not helpful

9

Bookmark this question.

View activity on this post.

I got this error while debugging my code:

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

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

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

  • php

Compare

Share a link to this question

Copy link CC BY-SA 3.0

Follow

Follow this question to receive notifications

modified on August 6, 2017 at 7:21 PM

Restore Monica's user avatar3167040

Restate Monica3167040

684 9 9 silver badges 23 23 bronze badges

requestedNovember 14, 2012 at 10:33 PM

User avatar of user1825110

user1825110 user1825110

535 1 1 gold badge 5 5 silver badges 6 6 bronze badges

0

Add a comment | 

3 answers3

Sorted by: Reset to default

High score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)

This answer is helpful

88

This answer is not helpful

View activity on this post.

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

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

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

Note the required pair of parentheses.

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

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

Compare

Share a link to this answer

Copy link CC BY-SA 4.0

Follow

Follow this answer to receive notifications

modified on March 6, 2020 at 1:27 PM

answeredNovember 14, 2012 at 10:36 PM

SirDarius user avatar

SirDarius SirDarius

39.8k 8 8 gold badges 84 84 silver badges 99 99 bronze badges

1

  • of them

    Even if he used his code on PHP 5.4 it would generate a syntax error.

    – Muntachir Akon

    October 15, 2015 at 1:48 PM

Add a comment | 

Report this ad

This answer is helpful

3

This answer is not helpful

View activity on this post.

change to because your syntax was not valid:

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

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

Compare

Share a link to this answer

Copy link CC BY-SA 3.0

Follow

Follow this answer to receive notifications

answeredNovember 14, 2012 at 10:34 PM

User avatar of Samuel Cook

Samuel CookSamuel Cook

16.2k 6 6 gold badges 48 48 silver badges 61 61 bronze badges

1

  • this code works for php version 4.9. But why does this error occur?

    – Madhourya Gandi

    June 5, 2017 at 9:09 PM

Add a comment | 

This answer is helpful

1

This answer is not helpful

View activity on this post.

You cannot use (this is invalid php syntax):

newPurchaseOrderFactory->instance();

You probably meant one of these:

// Initialize the new object of class PurchaseOrderFactory new PurchaseOrderFactory(); // Clone instance of existing PurchaseOrderFactory clone PurchaseOrderFactory::instance(); // Just use an instance PurchaseOrderFactory::instance(); // Initialize the new object and use one of its methods $tmp = new PurchaseOrderFactory(); $tmp->instance();

Compare

Share a link to this answer

Copy link CC BY-SA 3.0

Follow

Follow this answer to receive notifications

answered Nov 14, 2012 at 10:35 PM

Vyktor user avatar

Vyktor Vyktor

20.1k 5 5 gold badges 59 59 silver badges 95 95 bronze badges

Add a comment | 

Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Not the answer you’re looking for? Browse other questions tagged

  • php

or ask your own question.

  • The Overflow Blog
  • Five nines uptime without developer burnout (Ep. 488)

  • We hate Scrum and Agile…when it’s done wrong (Ep. 489)

  • Featured on Meta
  • Recent Color Contrast Changes and Accessibility Updates

  • Should I explain other people’s code-only answers?

  • Actualización de colectivos: miembros reconocidos, artículos y GitLab

  • Réviseur par-dessus bord ! Ou une demande d’amélioration du guide d’intégration pour les nouveaux…

Signaler cette annonce

Bondir

0

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in mail.php at line 4

0

Payload Object T Operator Error

1

Laravel Abstract Class Repository

0

Facebook Login PHP SDK 4.4

0

PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expects ‘)’

1

syntax error, unexpected T_OBJECT_OPERATOR? Facebook

1

CakePHP 3 showing blank white page

1

php – class DbQuery() and T_OBJECT_OPERATOR

-1

Partial amount of PHP visible on the web page

Related

2773

How can I prevent SQL injection in PHP?

2937

Removing an element from an array in PHP

2267

How do you parse and process HTML/XML in PHP?

4961

Reference — What does this symbol mean in PHP?

2229

How does PHP ‘foreach’ actually work?

1251

Reference – What does this error mean in PHP?

2673

Why shouldn’t I use mysql_* functions in PHP?

193

In PHP, why doesn’t </script> show a parse error?

298

What does yield mean in PHP?

752

PHP parsing/syntax errors; and how to solve them

burning questions from the net

  • Meaning of power consumption
  • Photodetector for short laser pulse
  • What is the bright orange star?
  • Laurent series in several complex variables
  • Non-transport factors
  • What video game is Spiderhead (2022) playing?
  • Fuzziness instead of specificity when the risks are huge
  • Send an email to a colleague in times of mourning
  • Stacking: Use training or testing predictions to build features for the Tier 1 classifier
  • Homotopy type of Diff(ℝP³)
  • Is it illegal to work for someone else while on paid leave?
  • What is the use case for disabling an index?
  • What is the area of ​​the SSME nozzle knowing only thrust at sea level and in a vacuum?
  • What is it called and what causes it? Bright reflections along the contrasting edges
  • Python decibels with metric precision?
  • In what situations could a “dirty water leak in” municipal water lines be other than a catastrophic pressure loss?
  • What is this component? White SMD part marked “W”
  • Is the minimization of a strictly convex function always strictly convex?
  • In which chamber of the United States Congress is a bill introduced first?
  • How to copy a list of file creation dates from a Windows File Explorer to a spreadsheet
  • Which is stronger: an ability that can be used during skill bonus periods or one that can be used once per short rest?
  • Does the key in which a piece is written affect the playability of the piano?
  • How do I request “open to”?
  • Counterexample that the arbitrary union of compact sets is compact

hotter questions

question flow

Subscribe to RSS

question flow

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


Video Syntax error unexpected t_object_operator

Related Posts

Free chat room code for my website

Contents1 How to set up a free chat room on the website.2 3 comentarios2.1 Trackbacks/Pingbacks2.2 Submit a Comment Cancel reply3 How to Create a Chat Room Website…

Background image full screen css

Contents1 Cómo – Full Page Image1.1 Example1.2 Example2 CSS background image tamaño tutorial: how to codify a complete page background image3 Perfect Full Page Background Image3.1 Méthode CSS géniale,…

WordPress leverage browser caching

Contents1 Aproveche el almacenamiento in hidden del navegador1.1 Will it works for my website?1.2 Where are plugin options1.3 Some JavaScript files still display under Leverage Browser Caching1.4…

WordPress post to facebook page

Contents1 How to Automatically Post to Facebook from WordPress1.1 Download Now: How to Launch a WordPress Website [Free Guide + Checklist]1.2 1. Create an IFTTT account.1.3 2….

Download images from wordpress media library

Contents1 How to export your WordPress media library1.1 Download maintenant : How to launch a WordPress website [Free Guide + Checklist]1.2 How to export your WordPress media…

WordPress single post template

Contents1 How to Create Custom Unique Post Templates in WordPress2 Post Template Files2.1 author.php2.2 Fecha.php3 Handbook navigation4 How to Create Custom Single Post Templates in WordPress5 Video…