Magic Methods in PHP ( __set() & __get() Used with array[] ) | Part -6

preview_player
Показать описание
Published on Dec 17, 2016

Playlist Name : Magic Methods in PHP Tutorial

__set() & __get() Used with array[]

In this tutorial we will learn about Magic Methods in PHP such as :

__set() :

1) set the value to Non-existing variables(private members of the class)

__get() :

2) Access Non-existing variables(private members of the class)

PHP __get And __set Magic Methods. PHP is a loosely typed programming language, one of the features of a loosely typed language is that you can use variables without declaring them or their type.

Don't forget to hit the Subscribe & Like button!
Рекомендации по теме
Комментарии
Автор

if you have any problem till now in this tutorial you can comment your
problem i will try to solve your problem thanks for watching and dont
forget to like and subscribe.

TechnicalSuneja
Автор

It will be very usefull, If u explain in English😶

harshilbalegar
Автор

i am getting the out put which is not the smae as yours even when i put the same code

vatsaljoshi
Автор

<?php

This is my code :

class A
{
private $array=['firstname'=>'vaibhav', 'age'=>13];
function __get($name)
{

echo "Trying to access non existing variable $name";
}


}
$obj=new A;
echo $obj->firstname;
?>


OUTPUT :

Trying to access non existing variable firstname


vatsaljoshi
Автор

thanks can you provide me the code of set function with argument also

vatsaljoshi