1

Below is the text from PHP Documentation :

Support for anonymous classes was added in PHP 7. Anonymous classes are useful when simple, one-off objects need to be created.

I didn't understand the meaning of the term 'one-off object' or rather 'simple one-off object' from the above text.

Someone please explain me the meaning of this term in a simple, lucid and easy to understand language.

Also, please explain me how the anonymous classes are useful when simple, one-off objects need to be created?

Do these 'one-off objects' or rather 'simple one-off objects' are used in live websites and applications?

  • Explained very well here https://www.phpclasses.org/blog/post/318-PHP-7-Anonymous-Classes-Tutorial.html – baig772 Dec 08 '17 at 12:40
  • @NicoHaase : The answers of question you linked are not explaining what does actually mean by 'one-off object' or rather 'simple one-off object' in PHP. So, please remove the Duplicate mark from my question. Please let someone answer who knows about this. Thank You. –  Dec 08 '17 at 12:41
  • @SerialKisser have a look at the definition of anonymous classes and then you'll see that "one-off objects" mean just that: instantiate an object on-the-fly without writing a usual class definition – Nico Haase Dec 08 '17 at 12:44
  • And no, this makes this question a duplicate of other questions. – Nico Haase Dec 08 '17 at 12:45
  • As a possible alternative to casting an arbitrary array to an object, just so that you can use object syntax to reference properties rather than array keys; you can create a "custom" object from an arbitrary array with methods (e.g. to create a read-only object) – Mark Baker Dec 08 '17 at 12:51

0 Answers0