Properties Overloading in PHP OOP | PHP OOP Lecture 9 | How to do this

Опубликовано: 12 Октябрь 2024
на канале: arbn Studios
363
8

Properties Overloading in PHP OOP, Overloading in PHP OOP, Method Overloading in PHP OOP
#PropertiesOverloadingInPhpOOP,#OverloadingInPhpOOP,#HowToDoThis


For further discussion please join our Facebook group:-
  / 1184520091737540  

For further updates please like our Facebook Page:-
  / web-learners-100953708317292  


Overloading :
Overloading in PHP provides means to dynamically "create" properties and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types.

The overloading methods are invoked when interacting with properties or methods that have not been declared or are not visible in the current scope. The rest of this section will use the terms "inaccessible properties" and "inaccessible methods" to refer to this combination of declaration and visibility.


Property overloading:


__set() is run when writing data to inaccessible (protected or private) or non-existing properties.

__get() is utilized for reading data from inaccessible (protected or private) or non-existing properties.

__isset() is triggered by calling isset() or empty() on inaccessible (protected or private) or non-existing properties.

__unset() is invoked when unset() is used on inaccessible (protected or private) or non-existing properties.

The $name argument is the name of the property being interacted with. The __set() method's $value argument specifies the value the $name'ed property should be set to.

Property overloading only works in object context. These magic methods will not be triggered in static context. Therefore these methods should not be declared static. As of PHP 5.3.0, a warning is issued if one of the magic overloading methods is declared static.


__call() is triggered when invoking inaccessible methods in an object context.

__callStatic() is triggered when invoking inaccessible methods in a static context.


PHP property overloading allows us to create dynamic properties in the object context. For creating those properties no separate line of code is needed. A property associated with the class instance, and it is not declared within the scope of the class, is considered as overloaded property.

We can perform the following operations with overloaded properties in PHP.

Setting and getting overloaded properties.
Evaluating overloaded properties setting.
Undo such properties setting.