<?php
class Maniple_Model
{
public function __construct(array $data = null)
{
if ($data) {
$this->setFromArray($data);
}
}
public function setFromArray(array $data)
{
foreach ($data as $key => $value) {
$this->__set($key, $value, false);
}
return $this;
}
/**
* @param string $key
* @return bool
*/
public function __isset($key) // {{{
{
return isset($this->{'_' . self::toCamelCase($key)});
} // }}}
/**
* @param string $key
* @return mixed
* @throws InvalidArgumentException
*/
public function __get($key) // {{{
{
$property = '_' . self::toCamelCase($key);
if (property_exists($this, $property)) {
return $property;
}
throw new InvalidArgumentException(sprintf('Invalid property: %s', $key));
} // }}}
/**
* @param string $key
* @param mixed $value
* @return void
* @throws InvalidArgumentException
*/
public function __set($key, $value, $throw = true) // {{{
{
$key = self::toCamelCase($key);
$setter = 'set' . $key;
if (method_exists($this, $setter)) {
$this->{$setter}($value);
return;
}
$property = '_' . $key;
if (property_exists($this, $property)) {
$this->{$property} = $value;
return;
}
throw new InvalidArgumentException(sprintf('Invalid property: %s', $key));
} // }}}
/**
* Transform given string to camel-case.
*
* @param string $str
* @return string
*/
public static function toCamelCase($str) // {{{
{
if (is_array($str) && isset($str[1])) {
return strtoupper($str[1]);
}
return preg_replace_callback(
'/_(\w)/', array(__CLASS__, __FUNCTION__), (string) $str
);
} // }}}
}
- Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.25
- Fatal error: Method Maniple_Model::__set() must take exactly 2 arguments in /in/ovXac on line 66
Process exited with code 255.
preferences:
181.86 ms | 1395 KiB | 62 Q