Answers for "magic method get php"

PHP
10

php magic methods

/*
The following function names are magical in PHP classes. 
You cannot have functions with these names in any of 
your classes unless you want the magic functionality 
associated with them.
*/
__construct(), 
__destruct(), 
__call(), 
__callStatic(), 
__get(), 
__set(),
__isset(), 
__unset(), 
__sleep(), 
__wakeup(), 
__serialize(),
__unserialize(), 
__toString(), 
__invoke(), 
__set_state(), 
__clone(), 
 __debugInfo()
Posted by: Guest on September-09-2020
0

magic method get php

<?php
 
class Person{
 private $firstName;
 
 public function __get($propertyName){
 echo "attempted to read non-existing property: $propertyName 
";
 } 
 public function __set($propertyNane, $propertyValue){
 echo "attempted to write to non-existing property: $propertyNane 
";
 } 
 
}
 
$p = new Person();
 
$p->firstName = 'Doe';
echo $p->firstName;
 
$p->lastName = 'John';
echo $p->lastName;
Posted by: Guest on September-24-2020

Browse Popular Code Answers by Language