I'm trying to use self
instead of typing the class name inside propery_exists
function as follows :
private static function instantiate($record){
$user = new self;
foreach($record as $name => $value){
if(isset($user->$name) || property_exists(self, $name)){
$user->$name = $value;
}
}
return $user;
}
But when i ran this script it get an error :
Notice: Use of undefined constant self - assumed 'self' in /var/www/photo_gallery/includes/User.php on line 36
Line 36 is the line where property_exists
method is called.
When i change self to User
(the class name). It works perfectly.
I want to know why using self
is giving such a notice ? Doesn't self
refer to the class?