@ 2017-08-17T09:42:46Z <?php
/*
* created on 1.2.2008
*/
class RootObj implements JsonSerializable
{
private $_data;
public function __construct($data = null)
{
$this->_data = $data;
}
public function &__get($name)
{
return $this->_data[$name];
}
public function __set($name, $value)
{
$this->_data[$name] = $value;
}
public function __isset($name)
{
return isset($this->_data[$name]);
}
public static function createObjectsFromArray($className, $array, $defaults = [], $idAsKey = false)
{
$results = [];
foreach ($array as $data) {
$result = new $className ($data);
if ($idAsKey) {
if (is_object($data) && isset($data->id)) {
$results[$data->id] = $result;
} else {
$results[$data['id']] = $result;
}
} else {
$results[] = $result;
}
foreach ((array)$defaults as $key => $value) {
$result->{$key} = $value;
}
}
return $results;
}
public function asArray()
{
return $this->_data;
}
public static function collectionToIds($collection)
{
$ids = [];
foreach ($collection as $item) {
$id = null;
if (is_array($item)) {
$id = $item['id'];
} else {
$id = $item->id;
}
if ($id != null) {
$ids[] = $id;
}
}
return $ids;
}
public function getSaveSql($table)
{
$sqlSnippets = [];
foreach ($this->_data as $key => $value) {
if ($key == 'id') {
continue;
}
if (is_array($value)) {
continue;
}
if (is_object($value)) {
continue;
}
if (is_bool($value)) {
$value = $value ? 1 : 0;
}
if ($value === null) {
$sqlSnippet = "{$key} = null";
} else {
$sqlSnippet = "{$key} = '" . addslashes($value) . "'";
}
$sqlSnippets[] = $sqlSnippet;
}
return ($this->_data['id'] > 0 ? 'update' : 'insert into') . " {$table} set " . implode(',', $sqlSnippets) . ($this->_data['id'] > 0 ? " where id = {$this->_data['id']}" : '');
}
/**
* @param string $propName
* @param null|string $lang
*
* @return string
*/
public function _($propName, $lang = null)
{
if ($lang === null) {
$lang = LangUtils::getLang();
}
$localizedPropName = "{$propName}_{$lang}";
if ($lang === null || $lang === 'cs') {
$localizedPropName = $propName;
}
return $this->{$localizedPropName};
}
public function __toString()
{
$out = get_class($this) . ': ';
$itemsTxt = [];
foreach (array_merge($this->_data, get_object_vars_compatible($this)) as $key => $value) {
$value = json_encode($value);
$itemsTxt[] = "{$key} = {$value}";
}
$out .= implode(',', $itemsTxt);
return $out;
}
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
// we do not want to include classes like Maternia_Translate or ServiceManager
$attr = get_object_vars_compatible($this);
foreach ($attr as $k => $a) {
if (is_object($a) && ! ($a instanceof stdClass)) {
unset($attr[$k]);
}
}
return add($this->_data, $attr);
}
public function __debugInfo()
{
$class = new \ReflectionClass($this);
$properties = [];
/** @var \ReflectionProperty $staticProperty */
foreach ($class->getStaticProperties() as $staticProperty) {
var_dump($staticProperty);
$staticProperty->setAccessible(true);
$properties[$staticProperty->getName()] = $staticProperty->getValue();
}
/** @var \ReflectionProperty $staticProperty */
foreach ($class->getProperties() as $property) {
$property->setAccessible(true);
$properties[$property->getName()] = $property->getValue($this);
}
var_dump($properties, $class->getParentClass());
$data = $properties['_data'];
unset($properties['_data']);
return array_merge($properties, $data);
}
}
$a = new RootObj();
$a->sfdgsdfg = 'sfgsdfg';
class Bb extends RootObj {
private $test = 'sdfs';
private static $sss = 'sdfs';
}
$b = new Bb();
$b->sfsdfgsdfg = 'asf';
var_dump($a, $b);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.016 0.003 18.52 8.3.5 0.012 0.003 16.63 8.3.4 0.009 0.006 18.96 8.3.3 0.012 0.009 18.85 8.3.2 0.004 0.004 20.16 8.3.1 0.000 0.008 21.96 8.3.0 0.004 0.004 20.84 8.2.18 0.012 0.003 18.41 8.2.17 0.009 0.006 22.96 8.2.16 0.004 0.011 19.58 8.2.15 0.005 0.003 24.18 8.2.14 0.008 0.000 24.66 8.2.13 0.008 0.000 19.43 8.2.12 0.004 0.004 26.35 8.2.11 0.007 0.004 19.26 8.2.10 0.000 0.012 18.09 8.2.9 0.003 0.006 22.39 8.2.8 0.006 0.003 19.48 8.2.7 0.000 0.008 17.93 8.2.6 0.004 0.004 18.03 8.2.5 0.006 0.003 18.16 8.2.4 0.004 0.004 20.47 8.2.3 0.000 0.008 19.45 8.2.2 0.003 0.005 18.25 8.2.1 0.000 0.008 18.20 8.2.0 0.000 0.008 18.18 8.1.28 0.010 0.010 25.92 8.1.27 0.005 0.003 22.27 8.1.26 0.004 0.004 26.35 8.1.25 0.005 0.003 28.09 8.1.24 0.006 0.003 19.40 8.1.23 0.006 0.006 21.10 8.1.22 0.005 0.003 17.91 8.1.21 0.004 0.004 20.75 8.1.20 0.000 0.008 17.48 8.1.19 0.005 0.003 17.48 8.1.18 0.006 0.003 18.10 8.1.17 0.005 0.003 18.74 8.1.16 0.000 0.007 18.84 8.1.15 0.004 0.004 20.58 8.1.14 0.004 0.004 19.65 8.1.13 0.000 0.007 20.61 8.1.12 0.007 0.003 17.51 8.1.11 0.005 0.003 17.45 8.1.10 0.003 0.007 17.52 8.1.9 0.000 0.008 17.57 8.1.8 0.004 0.004 17.61 8.1.7 0.000 0.009 17.42 8.1.6 0.006 0.003 17.51 8.1.5 0.006 0.003 17.52 8.1.4 0.006 0.003 17.57 8.1.3 0.008 0.000 17.74 8.1.2 0.003 0.006 17.64 8.1.1 0.003 0.005 17.63 8.1.0 0.000 0.008 17.64 8.0.30 0.005 0.003 19.80 8.0.29 0.005 0.003 17.00 8.0.28 0.007 0.000 18.43 8.0.27 0.007 0.000 17.32 8.0.26 0.000 0.008 18.97 8.0.25 0.003 0.003 17.02 8.0.24 0.000 0.008 17.11 8.0.23 0.000 0.008 17.13 8.0.22 0.005 0.003 17.03 8.0.21 0.003 0.004 17.02 8.0.20 0.005 0.003 17.02 8.0.19 0.009 0.000 17.03 8.0.18 0.004 0.004 17.06 8.0.17 0.005 0.002 17.06 8.0.16 0.003 0.005 17.14 8.0.15 0.004 0.004 17.04 8.0.14 0.007 0.000 17.00 8.0.13 0.003 0.003 13.45 8.0.12 0.005 0.003 16.88 8.0.11 0.003 0.005 16.93 8.0.10 0.003 0.005 17.10 8.0.9 0.003 0.005 17.04 8.0.8 0.013 0.007 17.02 8.0.7 0.004 0.004 17.10 8.0.6 0.005 0.002 17.00 8.0.5 0.000 0.007 17.02 8.0.3 0.012 0.007 17.34 8.0.2 0.009 0.012 17.42 8.0.1 0.006 0.003 16.97 8.0.0 0.011 0.007 16.78 7.4.33 0.003 0.003 15.55 7.4.32 0.000 0.006 16.63 7.4.30 0.003 0.003 16.69 7.4.29 0.007 0.003 16.67 7.4.28 0.004 0.004 16.59 7.4.27 0.005 0.003 16.61 7.4.26 0.004 0.004 16.55 7.4.25 0.003 0.005 16.55 7.4.24 0.000 0.007 16.72 7.4.23 0.007 0.000 16.59 7.4.22 0.029 0.012 16.79 7.4.21 0.006 0.008 16.66 7.4.20 0.000 0.007 16.52 7.4.16 0.004 0.011 16.52 7.4.15 0.003 0.014 17.40 7.4.14 0.011 0.009 17.86 7.4.13 0.014 0.011 16.70 7.4.12 0.013 0.007 16.59 7.3.33 0.002 0.005 13.32 7.3.32 0.003 0.003 13.57 7.3.31 0.000 0.007 16.53 7.3.30 0.000 0.007 16.49 7.3.29 0.007 0.000 16.33 7.3.28 0.007 0.010 16.48 7.3.27 0.012 0.006 17.40 7.3.26 0.016 0.005 16.72 7.3.25 0.008 0.014 16.46 7.3.24 0.012 0.008 16.58 7.1.8 0.242 0.023 16.57
preferences:dark mode live preview
54.78 ms | 401 KiB | 5 Q