-1

Sifting through the PHP documentation step by step, and I came across a discussion in the comments about ways to create empty objects other than instantiating a new instances of StdClass. However, I'm not sure what the point of ever creating an empty object is. Isn't the virtue of a class that it handily bundles together definitions you find yourself reusing often? Wouldn't an empty object that relies on having all values added onto it post hoc create the potential for serious inconsistencies?

user242007
  • 254
  • 2
  • 11
  • 1
    this question is purely theoretical, opinion-based and a duplicate of many questions, easily found by using the search feature, for example [this one](http://stackoverflow.com/questions/21353581/when-to-use-php-stdclass). or [that one](http://stackoverflow.com/questions/931407/what-is-stdclass-in-php) – Franz Gleichmann Jan 19 '17 at 18:45

1 Answers1

0

Quite often you need a property bag to throw key value pairs into. An answer to this is to use array, but why quoting all keys. Solution is to use dynamic properties on an instance of StdClass. This can have functions and normal key value as well.

Mitesh Pant
  • 544
  • 2
  • 15