protected function fetch() { $varName = $this->name->toString(); if ($this->class) { if ($this->class->isString()) { $ci = $this->executor->getClassStore()->get($this->class->getValue()); } else { if ($this->class->isObject()) { $ci = $this->class->getValue()->getClassEntry(); } else { throw new \RuntimeException('Class name must be a valid object or a string'); } } $this->zval = $ci->fetchStaticVariable($varName); } else { if (self::SCOPE_GLOBAL === $this->scope) { $symbolTable = $this->executor->executorGlobals->symbolTable; if (!isset($symbolTable[$varName])) { $this->zval = Zval::ptrFactory(); } else { $this->zval = $symbolTable[$varName]; } } else { if ($varName == 'this') { $this->zval = Zval::lockedPtrFactory($this->executor->getCurrent()->ci); } else { $this->zval = $this->executor->getCurrent()->fetchVariable($varName); } } } }
protected function callCallback($data, $mode) { if ($this->callback) { $this->buffer = ''; $current = $this->executor->getOutput(); $ro = new ReadOnly($this->executor); $this->executor->setOutput($ro); try { $ret = Zval::ptrFactory(); $args = array(Zval::ptrFactory($data), Zval::ptrFactory($mode)); $cb = $this->callback; $cb($this->executor, $args, $ret); } catch (\PHPPHP\Engine\ErrorOccurredException $e) { // Restore error handler first! $this->executor->setOutput($current); throw $e; } $this->executor->setOutput($current); if ($ret->isBool() || $ret->toBool() == false) { return $data; } else { return $ret->toString(); } } return $data; }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $this->op1->separateIfNotRef(); if (!$this->op1->isArray()) { if ($this->op1->isNull()) { $this->op1->setValue(array()); } else { throw new \RuntimeException('Cannot use a scalar value as an array'); } } $array =& $this->op1->getArray(); if ($this->dim) { $key = $this->dim->toString(); if (isset($array[$key])) { $array[$key]->forceValue($this->op2->getZval()); } else { $array[$key] = Zval::ptrFactory($this->op2->getZval()); } } else { $array[] = Zval::ptrFactory($this->op2->getZval()); } if ($this->result) { $this->result->setValue($this->op2->getZval()); } $data->nextOp(); }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $key = $this->op2->getValue(); if ($this->op1->isArray()) { $array =& $this->op1->getArray(); if (!isset($array[$key])) { if ($this->write) { $array[$key] = Zval::ptrFactory(); $this->result->setValue($array[$key]); } else { $this->result->setValue(Zval::ptrFactory()); } } else { $this->result->setValue($array[$key]); } } elseif ($this->op1->isString()) { $value = $this->op1->getValue(); if (isset($value[$key])) { $this->result->setValue($value[$key]); } else { $this->result->setValue(''); } } elseif ($this->write && $this->op1->isNull()) { $value = Zval::ptrFactory(); $this->op1->setValue(array($key => $value)); $this->result->setValue($value); } else { throw new \RuntimeException('Cannot use a scalar value as an array'); } if ($this->write) { $this->result->getZval()->makeRef(); } $data->nextOp(); }
public function setProperty($name, Zval $value) { if (isset($this->properties[$name])) { $this->properties[$name]->assignZval($value->getZval()); } else { $this->properties[$name] = Zval::ptrFactory($value->getZval()); } }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $args =& $data->arguments; $n = $this->op1->toLong(); if (!isset($args[$n])) { $args[$n] = Zval::ptrFactory($this->op2->getZval()); } parent::execute($data); }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $varName = $this->op1->toString(); if (!isset($data->executor->executorGlobals->symbolTable[$varName])) { $data->executor->executorGlobals->symbolTable[$varName] = Zval::ptrFactory(); } $data->symbolTable[$varName] = $data->executor->executorGlobals->symbolTable[$varName]; $data->nextOp(); }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $name = $this->op1->toString(); $functionData = $this->op2; $ce = $data->executor->getClassStore()->get('Closure'); $ci = $ce->instantiate($data, array('functionData' => Zval::ptrFactory($functionData))); if ($this->result) { $this->result->setValue($ci); } $data->nextOp(); }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $key = $this->op1->toString(); $array = $this->result->toArray(); $var = Zval::ptrFactory($this->op2->getZval())->separateIfRef(); if ($key) { $array[$key] = $var; } else { $array[] = $var; } $this->result->setValue($array); $data->nextOp(); }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $functionCall = $data->executor->executorGlobals->call; $args = array(); $stack = $data->executor->getStack(); for ($i = $stack->count() - 1; $i >= 0; $i--) { $args[] = $stack->pop(); } $args = array_reverse($args); if (!$this->result) { $this->result = Zval::ptrFactory(); } $functionCall->execute($args, $this->result); $data->executor->executorGlobals->call = null; $data->nextOp(); }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $ptr = null; if ($data->executor->executorGlobals->call->getFunction()->isArgByRef($this->op2->getValue())) { if ($this->op1->isVariable() || $this->op1->isRef() || $this->op1->isObject()) { $op = $this->op1->getPtr(); $op->makeRef(); $op->addRef(); $ptr = Zval::ptrFactory($op->getZval()); } else { throw new \RuntimeException("Can't pass parameter {" . $this->op2->getValue() . "} by reference"); } } else { $ptr = Zval::ptrFactory($this->op1->getValue()); } $data->executor->getStack()->push($ptr); $data->nextOp(); }
protected function setValue($value) { $zval = Zval::factory($value); if ($this->property) { $this->op1->getValue()->setProperty($this->property->toString(), $zval); } else { if ($this->dim) { $array =& $this->op1->getArray(); $key = $this->dim->toString(); if (isset($array[$key])) { $array[$key]->setValue($zval); } else { $array[$key] = Zval::ptrFactory($zval); } } else { $this->op1->setValue($zval); } } if ($this->result) { $this->result->setValue($zval); } }
public function callMethod(ExecuteData $data, ClassInstance $ci = null, $name = '', array $args = array(), Ptr $result = null) { $method = $this->findMethod($name); if (!$result) { $result = Zval::ptrFactory(); } $method->execute($data->executor, $args, $result, $ci); }
protected function compileFunction($node) { $prevOpArray = $this->opArray; $this->opArray = new OpArray($this->fileName); $params = array(); foreach ($node->params as $i => $param) { $type = null; if ($param->type && $param->type instanceof \PHPParser_Node) { $tmpZval = Zval::ptrFactory(); $this->compileChild($param, 'type', $tmpZval); $type = $tmpZval->toString(); } elseif (is_string($param->type)) { $type = $param->type; } $params[] = new ParamData($param->name, $param->byRef, $type, (bool) $param->default, $node->getLine()); if ($param->default) { $default = Zval::ptrFactory(); $this->compileChild($param, 'default', $default); if ($param->type == 'array' && !($default->isArray() || $default->isNull())) { throw new CompileException('Default value for parameters with array type hint can only be an array or NULL', $node->getLine()); } elseif ($param->type != 'array' && $param->type && !$default->isNull()) { throw new CompileException('Default value for parameters with a class type hint can only be NULL', $node->getLine()); } $this->opArray[] = new OpLines\RecvInit($node->getLine(), Zval::factory($i), $default); } else { $this->opArray[] = new OpLines\Recv($node->getLine(), Zval::factory($i)); } } $this->compileChild($node, 'stmts'); $this->opArray[] = new OpLines\ReturnOp($node->getLine()); $funcData = new FunctionData\User($this->opArray, (bool) $node->byRef, $params); $this->opArray = $prevOpArray; return $funcData; }
protected function checkParams(\PHPPHP\Engine\Executor $executor, array &$args, $checkTooMany = false) { $argNo = 0; $required = 0; $hasOptional = false; $has = count($args); $varargs = false; while ($param = $this->getParam($argNo)) { if ($param->type) { $error = ""; if ($param->type == 'array') { if (!isset($args[$argNo]) && !$param->isOptional) { $error = "array"; } elseif (!isset($args[$argNo])) { // Blank intentional } elseif (!$args[$argNo]->isArray() && !($args[$argNo]->isNull() && $param->isOptional)) { $error = "array"; } } elseif ($param->type == 'callable') { //bypass the callable check for now... } else { if (!isset($args[$argNo]) && !$param->isOptional) { $error = "instance of {$param->type}"; } elseif (!isset($args[$argNo])) { // Blank intentional } elseif (!$args[$argNo]->isObject() && !($args[$argNo]->isNull() && $param->isOptional)) { $error = "instance of {$param->type}"; } elseif (!$args[$argNo]->isObject()) { // Blank intentional } elseif (!$args[$argNo]->getValue()->getClassEntry()->isInstanceOf($param->type)) { $error = "instance of {$param->type}"; } } if ($error) { $type = "none"; if (isset($args[$argNo])) { $type = $args[$argNo]->getType(); if ($type == 'object') { $type = 'instance of ' . $args[$argNo]->getValue()->getClassEntry()->getName(); } } $extra = ''; if ($this->getFileName()) { $extra = ' and defined in ' . $this->getFileName() . ' on line ' . $param->lineno; } $message = "Argument " . ($argNo + 1) . " passed to {$this->name}() must be an {$error}, {$type} given, called"; $executor->raiseError(E_RECOVERABLE_ERROR, $message, $extra, false); } } if (!$param->isOptional) { $required++; if (!isset($args[$argNo])) { $args[$argNo] = Engine\Zval::ptrFactory(); } } else { $hasOptional = true; } if ($param->name == '...') { $varargs = true; } $argNo++; } if ($required > $has) { $message = $this->name; $message .= "() expects "; $message .= $hasOptional ? "at least" : "exactly"; $message .= " {$required} " . ($required == 1 ? "parameter" : "parameters"); $message .= ", {$has} given"; $executor->raiseError(E_WARNING, $message, '', false); return false; } elseif ($checkTooMany && !$varargs && $has > $argNo) { $message = $this->name; $message .= "() expects "; $message .= $hasOptional ? "at most" : "exactly"; $message .= " {$argNo} " . ($argNo == 1 ? "parameter" : "parameters"); $message .= ", {$has} given"; $executor->raiseError(E_WARNING, $message, '', false); return false; } return true; }
public function toObject(ExecuteData $data) { if ($this->isObject()) { return $this->value; } else { if ($this->isArray()) { $properties = $this->value; } else { $properties = array('scalar' => Zval::ptrFactory($this->value)); } $ce = $data->executor->getClassStore()->get('stdClass'); return $ce->instantiate($data, $properties); } }