本文整理汇总了PHP中Photograph::has_attribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Photograph::has_attribute方法的具体用法?PHP Photograph::has_attribute怎么用?PHP Photograph::has_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Photograph
的用法示例。
在下文中一共展示了Photograph::has_attribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: instantiate
public static function instantiate($record)
{
// Check if $record exists and is an array
// $object = new User();
// $object = new self;
$object = new Photograph();
// Short Method
foreach ($record as $attribute => $value) {
// Why check ???
if ($object->has_attribute($attribute)) {
// See the syntax of attribute here with $ - dynamic variable
$object->{$attribute} = $value;
}
// return $object; -- ThIS IS WRONG WRONG
}
//BE VERY VERY CAREUL WHERE U R RETURNING YOUR OBJECT
// HERE I LOST 1 HOUR BCOZ OF THAT MISTAKE
return $object;
// Long method
// not required here ---> $record = User::find_by_id(1);
// $object->username = $record['username'];
// $object->password = $record['password'];
// $object->first_name = $record['first_name'];
// $object->last_name = $record['last_name'];
// $object->id = $record['id'];
}