Taste Of JavaScript In Php Part-2 (Php 5.4+)

A few days ago I’ve posted an article, titled Taste Of JavaScript In Php (as my random ideas) where I wrote a class to create dynamic Php objects in the run time and it requires Php 5.4+ and this is another follow up of that article, the updated version of stdObject class, which requires Php 5.4+ and also supports some new features.

The old one is capable of creating dynamic objects at run time and also it can copy/clone other objects (typeof stdObjec) but this one is also capable of inherit other (typeof stdObject) objects and can change properties of the inherited object (by reference), it means, if any changes is made in the new object then the changes reflect on thr parent object too and also supports private properties but using a different approach. So here is the ugly code :

Basic Example/Usage :

Create an instance with values in array :

Create another object from an old object :

Create another object from $anotherCls and inherit (by reference) all it’s functionality.

Copy/Clone a new one from old one (used Clone) :

You may use pivate properies too :

It’s possible to use private properties using an underscore _ but you can retrieve it without the underscore (Sorry for this hack) :p

Well, that’s it. This is just my random idea from my random (maybe good for nothing) thoughts and if you like it then it’s well but if you don’t like it then it’s also very well and if you have any feedback or can improve (if you are mad like me) it in any way then it’s really very very well.

→ The old version (another WTF) is here.

Latest Blog


PHP – 8.0 Match Expression

In PHP 8.0 there is a new feature or I should say a new language construct (keyword) going to be introduced,  which has been implemented depending […]


New Union Type in PHP – 8

A new RFC has been finished voting and accepted for PHP – 8. That is “Union Types”, which is an extension of PHP’s type system. […]