/** * main function * @param $find * @param $replace * @param $array * @param bool $t * @param string $for * @param bool $init * @param null $c * @return array */ public function &find_replace($find, $replace, &$array, $t = true, $for = 'value', $init = true, &$c = null) { static $h = array(); //draft static $result = array(); //main result main static $draft_result_paths = array(); //purpose for draft static $paths = array(); //all paths found in array if ($init) { $h = array(); $result = array(); $paths = array(); $draft_result_paths = array(); } $valid_recursive = true; //valid recursive while ($valid_recursive) { if (!$c) { $o =& $array; } else { $o =& $c[1]; } //fetch array remain if (is_array($o)) { foreach ($o as $key => &$v) { if (is_array($v)) { if (isset($v->O)) { $v = $v->O; } $h[] = array($key, &$v); //save this item of array for map location of array if ($c) { //save path & valid for it $path = $c[0] . '/' . $key; //prep path for this key if (!count($paths) && !isset($draft_result_paths[$path])) { $paths[] = $path; $draft_result_paths[$path] = 1; //track path } if (!find_replace_check($paths, $c[0], $key)) { foreach ($paths as $u) { if (false !== strpos($u, $c[0])) { $tt = 1; } } if (!isset($tt) && !isset($draft_result_paths[$path])) { $paths[] = $path; $draft_result_paths[$path] = 1; //track path } } } } /*search for value or key*/ $xpath = $c[0] . '/' . $key; if ($for == 'value' && ($find == 'H_OBJECT' ? 'object' : gettype($find)) == gettype($v) && ($find == 'H_OBJECT' ? true : $v === $find) || $for == 'key' && $find === $key) { if (!count($paths) && !isset($draft_result_paths[$xpath])) { $result[] = array(&$v, $xpath); //if no any array in deep, get a result $draft_result_paths[$xpath] = 1; //save this path of result } foreach ($paths as $path) { if (false !== strpos($path, $xpath) && $path !== $xpath && self::valid_result_path($path, $v, $array, $for)) { if (!isset($draft_result_paths[$path])) { $result[] = array(&$v, $path); $m = 1; $draft_result_paths[$path] = 1; //save this path of result } } } if (!isset($m)) { foreach ($paths as $path) { $w = explode('/', $path); if ($w[count($w) - 1] == $c[0] && self::valid_result_path($path . '/' . $key, $v, $array, $for)) { $new_path = $path . '/' . $key; //get new path if (!isset($draft_result_paths[$new_path])) { $result[] = array(&$v, $new_path); $draft_result_paths[$new_path] = 1; //save this path of result } } if ($w[count($w) - 2] === $c[0] && self::valid_result_path(join($w, '/') . '/' . $key, $v, $array, $for)) { array_pop($w); $new_path = join($w, '/') . '/' . $key; //get new path if (!isset($draft_result_paths[$new_path])) { $result[] = array(&$v, $new_path); $draft_result_paths[$new_path] = 1; //save this path of result } } } } if ($t) { $o[$key] = $find == 'COPY_OF_IT' ? _clone($o[$key]) : $find; } } } } if (count($h) && ($n =& $h[0]) && array_shift($h)) { $c =& $n; if (isset($n->O)) { $c =& $n->O; } //for DRW class instance } else { $valid_recursive = false; } } $jo = array($result, $paths); return $jo; }
function &find_replace($a, $b, &$d, $t = true, $for = 'value', $init = true, &$c = null) { static $h = array(); static $r = array(); static $y = array(); if ($init) { $h = array(); $r = array(); $y = array(); } if (!$c) { $o =& $d; } else { $o =& $c[1]; } if (is_array($o)) { foreach ($o as $i => &$v) { if (is_array($v) || isDrw($v)) { if (isset($v->O)) { $v =& $v->O; } $h[] = array($i, &$v); if ($c) { $path = $c[0] . '/' . $i; if (!count($y)) { $y[] = $path; } if (!find_replace_check($y, $c[0], $i)) { foreach ($y as $u) { if (false !== strpos($u, $c[0])) { $tt = 1; } } if (!isset($tt)) { $y[] = $path; } } } } /*search for value or key*/ $xpath = $c[0] . '/' . $i; if ($for == 'value' && ($a == H_OBJECT ? 'object' : gettype($a)) == gettype($v) && ($a == H_OBJECT ? true : $v === $a) || $for == 'key' && isStr($a) && $a === $i) { if (!count($y)) { $r[] = array(&$v, $xpath); } foreach ($y as $z) { if (false !== strpos($z, $xpath)) { $r[] = array(&$v, $z); $m = 1; } } if (!isset($m)) { foreach ($y as $z) { $w = explode('/', $z); if ($w[count($w) - 1] == $c[0]) { $r[] = array(&$v, $z . '/' . $i); } if ($w[count($w) - 2] == $c[0]) { pop($w); $r[] = array(&$v, join($w, '/') . '/' . $i); } } } if ($t) { $o[$i] = $b == COPY_OF_IT ? _clone($o[$i]) : $b; } } } } if (count($h) && ($n =& $h[0]) && array_shift($h)) { if (isset($n->O)) { $n =& $n->O; } find_replace($a, $b, $d, $t, $for, false, $n); } $jo = array($r, $y); return $jo; }
/** * Compares two blank nodes for equivalence. * * @param a the first blank node. * @param b the second blank node. * * @return -1 if a < b, 0 if a == b, 1 if a > b. */ public function deepCompareBlankNodes($a, $b) { $rval = 0; // compare IRIs $iriA = $a->{__S}->{'@iri'}; $iriB = $b->{__S}->{'@iri'}; if ($iriA === $iriB) { $rval = 0; } else { // do shallow compare first $rval = $this->shallowCompareBlankNodes($a, $b); // deep comparison is necessary if ($rval === 0) { // compare property edges and then reference edges $dirs = array('props', 'refs'); for ($i = 0; $rval === 0 and $i < 2; ++$i) { // recompute 'a' and 'b' serializations as necessary $dir = $dirs[$i]; $sA = $this->serializations->{$iriA}; $sB = $this->serializations->{$iriB}; if ($sA->{$dir} === null) { $mb = new MappingBuilder(); if ($dir === 'refs') { // keep same mapping and count from 'props' serialization $mb->mapping = _clone($sA->props->m); $mb->count = count(array_keys((array) $mb->mapping)) + 1; } $this->serializeBlankNode($sA, $iriA, $mb, $dir); } if ($sB->{$dir} === null) { $mb = new MappingBuilder(); if ($dir === 'refs') { // keep same mapping and count from 'props' serialization $mb->mapping = _clone($sB->props->m); $mb->count = count(array_keys((array) $mb->mapping)) + 1; } $this->serializeBlankNode($sB, $iriB, $mb, $dir); } // compare serializations $rval = _compare($sA->{$dir}->s, $sB->{$dir}->s); } } } return $rval; }
var_dump($method); var_dump($arguments); }), _public('__set', function ($key, $value) { $data = _this('storage'); $data[(string) $key] = $value; _this('storage', $data); return $value; }), _public('__get', function ($key) { $data = _this('storage'); return isset($data[$key]) ? $data[$key] : null; }), _public('__clone', function () { _this('storage', array()); }))); _call('MyClass::my_static_function()', 'Not "Hello from static private"'); // output: string(18) "my_static_function" array(1) { [0]=> string(31) "Not "Hello from static private"" } $obj = _new('MyClass'); // output: int(1) _call($obj, 'my_function()', 'Not "Hello from private"'); // output: string(13) "my_function()" array(1) { [0]=> string(24) "Not "Hello from private"" } var_dump(_prop($obj, 'my_prop')); // output: NULL var_dump(_prop($obj, 'my_prop', 100)); // output: 100 var_dump(_prop($obj, 'my_prop')); // output: 100 $clone = _clone($obj); var_dump(_prop($clone, 'my_prop')); // output: NULL // Execute destructors // output: int(0) // output: int(0)
function _doInheritance() { if (!is_null($this->_inherit_parent)) { // Found a "Inherits", now duplicate the children of it's // "parent class" and add it to this $results =& $this->Project->lookup($this->_inherit_parent, $this); if (count($results) > 0) { // Make sure the parent's inheritances are resolved before // we continue $results[0]->_doInheritance(); // This next line will duplicate the children SUPPOSEDLY $childrenx = $results[0]->getChildren(); $children = array(); foreach ($childrenx as $child) { $children[] = _clone($child); } foreach ($children as &$child) { // If there's already something with the same name, norget it foreach ($this->getChildren() as $other_child) { if ($other_child->getType() == $child->getType() && $other_child->getTitle() == $child->getTitle()) { continue 2; } } $child->_tags[] = 'inherited'; // Add to subgroups and children $this->registerChild($child); // Cheap version of ScProject::register() $this->Project->data['blocks'][] =& $child; } } } }