public function fetchVariable($name) { if (!isset($this->symbolTable[$name])) { $this->symbolTable[$name] = Zval::ptrFactory(); } return $this->symbolTable[$name]; }
function PHP_debug_print_backtrace(Executor $executor, array $args) { $return = Zval::ptrFactory(); PHP_debug_backtrace($executor, $args, $return); $output = $executor->getOutput(); $frames = $return->toArray(); foreach ($frames as $num => $stackFrame) { if (isset($stackFrame['function'])) { $class = isset($stackFrame['class']) ? $stackFrame['class'] : ''; $class .= isset($stackFrame['type']) ? $stackFrame['type'] : ''; $args = ''; $sep = ''; foreach ($stackFrame['args'] as $arg) { $args .= $sep . $arg->makePrintable()->getValue(); $sep = ', '; } $line = "#{$num} {$class}{$stackFrame['function']}({$args}) called at [{$stackFrame['file']}:{$stackFrame['line']}]"; } else { $line = "#{$num} include() [{$stackFrame['file']}:{$stackFrame['line']}]"; } $output->write($line . "\n"); } }
public function execute(\PHPPHP\Engine\ExecuteData $data) { $this->op2->makeRef(); $zval = $this->op2->getZval(); if ($this->property) { $this->op1->getValue()->setProperty($this->property->toString(), $zval); } else { if ($this->dim) { $array =& $this->op1->getArray(); $key = $this->property->toString(); if (isset($array[$key])) { $array[$key]->forceValue($zval); } else { $array[$key] = Zval::ptrFactory($zval); } } else { $this->op1->forceValue($zval); } } if ($this->result) { $this->result->setValue($zval); } $data->nextOp(); }
while ($buffer instanceof Output\Buffer) { $buffer = $buffer->getParent(); $level++; } $return->setValue($level); }), 'ob_list_handlers' => new FunctionData\Internal(function (Executor $executor, array $args, Zval $return) { $ret = array(); $buffer = $executor->getOutput(); do { if ($buffer instanceof Output\Buffer) { $cb = $buffer->getCallback(); if ($cb) { $ret[] = Zval::ptrFactory('callback'); continue; } $ret[] = Zval::ptrFactory('default output handler'); } } while ($buffer = $buffer->getParent()); $return->setValue(array_reverse($ret)); }), 'ob_flush' => new FunctionData\Internal(function (Executor $executor, array $args, Zval $return) { $buffer = $executor->getOutput(); try { $buffer->flush(); $return->setValue(true); } catch (\LogicException $e) { if ($e->getMessage() == 'Unflushable Buffer') { $executor->raiseError(E_NOTICE, 'failed to flush buffer of callback (0)'); $return->setValue(false); } else { var_dump($e->getMessage()); throw $e;
<?php namespace PHPPHP\Engine; $closureMethods = array('__invoke' => new FunctionData\Internal(function (Executor $ex, array $params, Zval $return, Objects\ClassInstance $ci) { $fd = $ci->getProperty('functionData'); $fd->execute($ex, $params, $return); }, false, array())); $closureProperties = array('functionData' => array('default' => Zval::ptrFactory(null), 'access' => Scope::ACC_PRIVATE | Scope::ACC_INTERNAL)); return array('Closure' => array('methods' => $closureMethods, 'properties' => $closureProperties));
public function execute(OpArray $opArray, array &$symbolTable = array(), FunctionData $function = null, array $args = array(), Zval $result = null, Objects\ClassInstance $ci = null) { $shutdownScope = $this->shutdown; if ($this->shutdown == self::FINISHED_SHUTDOWN) { return; } $opArray->registerExecutor($this); $scope = new ExecuteData($this, $opArray, $function); $scope->arguments = $args; $scope->ci = $ci; $preExecute = $this->preExecute; $postExecute = $this->postExecute; if ($this->current) { $scope->parent = $this->current; } $this->current = $scope; if ($symbolTable || $function) { $scope->symbolTable =& $symbolTable; } else { $scope->symbolTable =& $this->executorGlobals->symbolTable; } $scope->returnValue = $result ?: Zval::ptrFactory(); if ($function && $function->isByRef()) { $scope->returnValue->makeRef(); } while ($this->shutdown == $shutdownScope && $scope->opLine) { if ($preExecute) { call_user_func($preExecute, $scope); } $ret = $scope->opLine->execute($scope); if ($postExecute) { call_user_func($postExecute, $scope, $ret); } if ($this->shutdown == $shutdownScope && $this->executorGlobals->timeLimit && $this->executorGlobals->timeLimitEnd < time()) { $limit = $this->executorGlobals->timeLimit; $message = sprintf('Maximum execution time of %d second%s exceeded', $limit, $limit == 1 ? '' : 's'); $this->errorHandler->handle($this, E_ERROR, $message, $opArray->getFileName(), $scope->opLine->lineno, '', false); return; } switch ($ret) { case self::DO_RETURN: $this->current = $this->current->parent; return; case self::DO_SHUTDOWN: $this->shutdown(); return; } } if ($this->shutdown) { return; } die('Should never reach this point!'); }
public function __construct() { $globalsPtr = Zval::ptrFactory(array()); $this->symbolTable =& $globalsPtr->getArray(); $this->symbolTable['GLOBALS'] = $globalsPtr; }