Exemple #1
0
function var_dump_internal(Executor $executor, Zval $arg, $indent = '')
{
    if ($arg->getValue() instanceof FunctionData) {
        return '';
    }
    $output = $indent;
    switch ($arg->getType()) {
        case 'NULL':
            $output .= 'NULL';
            break;
        case 'string':
            $length = strlen($arg->getValue());
            $output .= 'string(' . $length . ') "' . $arg->getValue() . '"';
            break;
        case 'integer':
            $output .= 'int(' . $arg->getValue() . ')';
            break;
        case 'double':
            $output .= 'float(' . $arg->getValue() . ')';
            break;
        case 'boolean':
            $output .= 'bool(' . ($arg->getValue() ? 'true' : 'false') . ')';
            break;
        case 'array':
            $array = $arg->getArray();
            $output .= 'array(' . count($array) . ") {\n";
            $newIndent = $indent . '  ';
            foreach ($array as $key => $value) {
                if (is_string($key)) {
                    $output .= $newIndent . "[\"{$key}\"]=>\n";
                } else {
                    $output .= $newIndent . "[{$key}]=>\n";
                }
                $output .= var_dump_internal($executor, $value, $newIndent);
            }
            $output .= $indent . "}";
            break;
        case 'object':
            $ci = $arg->getValue();
            $props = $ci->getProperties();
            $output = 'object(' . $ci->getClassEntry()->getName() . ')#' . $ci->getInstanceNumber();
            $output .= ' (' . count($props) . ") {\n";
            $newIndent = $indent . '  ';
            foreach ($props as $key => $value) {
                if (is_string($key)) {
                    $output .= $newIndent . "[\"{$key}\"]=>\n";
                } else {
                    $output .= $newIndent . "[{$key}]=>\n";
                }
                $output .= var_dump_internal($executor, $value, $newIndent);
            }
            $output .= $indent . "}";
            break;
    }
    return $output . "\n";
}
Exemple #2
0
 public function fetchVariable($name)
 {
     if (!isset($this->symbolTable[$name])) {
         $this->symbolTable[$name] = Zval::ptrFactory();
     }
     return $this->symbolTable[$name];
 }
Exemple #3
0
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");
    }
}
Exemple #4
0
 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();
 }
Exemple #5
0
    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;
Exemple #6
0
<?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));
Exemple #7
0
 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!');
 }
Exemple #8
0
 public function __construct()
 {
     $globalsPtr = Zval::ptrFactory(array());
     $this->symbolTable =& $globalsPtr->getArray();
     $this->symbolTable['GLOBALS'] = $globalsPtr;
 }