本文整理汇总了PHP中Zephir\Variable::isReadOnly方法的典型用法代码示例。如果您正苦于以下问题:PHP Variable::isReadOnly方法的具体用法?PHP Variable::isReadOnly怎么用?PHP Variable::isReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zephir\Variable
的用法示例。
在下文中一共展示了Variable::isReadOnly方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assign
/**
* Compiles x--
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompilationContext $compilationContext
* @param array $statement
*/
public function assign($variable, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
if ($symbolVariable->isReadOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
}
$codePrinter = $compilationContext->codePrinter;
switch ($symbolVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
case 'char':
case 'uchar':
$codePrinter->output($variable . '--;');
break;
case 'variable':
/**
* Variable is probably not initialized here
*/
if ($symbolVariable->hasAnyDynamicType('unknown')) {
throw new CompilerException("Attempt to increment uninitialized variable", $statement);
}
/**
* Decrement non-numeric variables could be expensive
*/
if (!$symbolVariable->hasAnyDynamicType(array('undefined', 'int', 'long', 'double', 'uint'))) {
$compilationContext->logger->warning('Possible attempt to decrement non-numeric dynamic variable', 'non-valid-decrement', $statement);
}
$compilationContext->headersManager->add('kernel/operators');
if ($symbolVariable->isLocalOnly()) {
$codePrinter->output('zephir_decrement(&' . $variable . ');');
} else {
$symbolVariable->separate($compilationContext);
$codePrinter->output('zephir_decrement(' . $variable . ');');
}
break;
default:
throw new CompilerException("Cannot decrement variable: " . $symbolVariable->getType(), $statement);
}
}
示例2: assign
/**
* Compiles x++
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompilationContext $compilationContext
* @param array $statement
*
* @throws CompilerException
*/
public function assign($variable, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
if ($symbolVariable->isReadOnly()) {
/**
* @TODO implement increment of objects members
*/
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
}
$codePrinter =& $compilationContext->codePrinter;
switch ($symbolVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
case 'char':
case 'uchar':
$codePrinter->output($variable . '++;');
break;
case 'variable':
/**
* Update non-numeric dynamic variables could be expensive
*/
if (!$symbolVariable->hasAnyDynamicType(array('undefined', 'long', 'double'))) {
$compilationContext->logger->warning('Possible attempt to increment non-numeric dynamic variable', 'non-valid-increment', $statement);
}
$compilationContext->headersManager->add('kernel/operators');
if (!$symbolVariable->isLocalOnly()) {
$symbolVariable->separate($compilationContext);
}
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
$codePrinter->output('zephir_increment(' . $symbol . ');');
break;
default:
throw new CompilerException("Cannot increment: " . $symbolVariable->getType(), $statement);
}
}
示例3: assign
/**
* Compiles foo = {expr}
* Changes the value of a mutable variable
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param ReadDetector $readDetector
* @param CompilationContext $compilationContext
* @param array $statement
* @throws CompilerException
*/
public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, ReadDetector $readDetector, CompilationContext $compilationContext, array $statement)
{
if ($symbolVariable->isReadOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
}
$codePrinter = $compilationContext->codePrinter;
/**
* Only initialize variables if it's direct assignment
*/
if ($statement['operator'] == 'assign') {
$symbolVariable->setIsInitialized(true, $compilationContext, $statement);
} else {
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
}
/**
* Set the assigned value to the variable as a CompiledExpression
* We could use this expression for further analysis
*/
$symbolVariable->setPossibleValue($resolvedExpr, $compilationContext);
$type = $symbolVariable->getType();
switch ($type) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'char':
case 'uchar':
$this->doNumericAssignment($codePrinter, $resolvedExpr, $symbolVariable, $variable, $statement, $compilationContext);
break;
case 'double':
$this->doDoubleAssignment($codePrinter, $resolvedExpr, $symbolVariable, $variable, $statement, $compilationContext);
break;
case 'array':
$this->doArrayAssignment($codePrinter, $resolvedExpr, $symbolVariable, $variable, $statement, $compilationContext);
break;
case 'string':
$this->doStringAssignment($codePrinter, $resolvedExpr, $symbolVariable, $variable, $statement, $compilationContext);
break;
case 'bool':
$this->doBoolAssignment($codePrinter, $resolvedExpr, $symbolVariable, $variable, $statement, $compilationContext);
break;
case 'variable':
$this->doVariableAssignment($codePrinter, $resolvedExpr, $symbolVariable, $variable, $statement, $compilationContext, $readDetector);
break;
default:
throw new CompilerException("Unknown type: " . $type, $statement);
}
}
示例4: assign
/**
* Compiles foo[y] = {expr}
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param array $statement
*/
public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
{
/**
* Arrays must be stored in the HEAP
*/
if ($symbolVariable->isLocalOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
}
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
if ($symbolVariable->isReadOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
}
if ($symbolVariable->isLocalOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
}
/**
* Only dynamic variables can be used as arrays
*/
if ($symbolVariable->isNotVariableAndArray()) {
throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
}
if ($symbolVariable->getType() == 'variable') {
if ($symbolVariable->hasAnyDynamicType('unknown')) {
throw new CompilerException("Cannot use non-initialized variable as an object", $statement);
}
/**
* Trying to use a non-object dynamic variable as object
*/
if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'array', 'null'))) {
$compilationContext->logger->warning('Possible attempt to update index on a non-array dynamic variable', 'non-array-update', $statement);
}
}
/**
* Choose one-offset or multiple-offset functions
*/
if (count($statement['index-expr']) == 1) {
$this->_assignArrayIndexSingle($variable, $symbolVariable, $resolvedExpr, $compilationContext, $statement);
} else {
$this->_assignArrayIndexMultiple($variable, $symbolVariable, $resolvedExpr, $compilationContext, $statement);
}
}
示例5: assign
/**
* Compiles foo = {expr}
* Changes the value of a mutable variable
*
* @param $variable
* @param Variable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param ReadDetector $readDetector
* @param CompilationContext $compilationContext
* @param $statement
* @throws CompilerException
*/
public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, ReadDetector $readDetector, CompilationContext $compilationContext, $statement)
{
if ($symbolVariable->isReadOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
}
$codePrinter = $compilationContext->codePrinter;
/**
* Only initialize variables if it's direct assignment
*/
if ($statement['operator'] == 'assign') {
$symbolVariable->setIsInitialized(true, $compilationContext, $statement);
} else {
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
}
/**
* Set the assigned value to the variable as a CompiledExpression
* We could use this expression for further analysis
*/
$symbolVariable->setPossibleValue($resolvedExpr, $compilationContext);
$type = $symbolVariable->getType();
switch ($type) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'char':
case 'uchar':
switch ($resolvedExpr->getType()) {
case 'null':
switch ($statement['operator']) {
case 'assign':
$codePrinter->output($variable . ' = 0;');
break;
case 'add-assign':
$codePrinter->output($variable . ' += 0;');
break;
case 'sub-assign':
$codePrinter->output($variable . ' -= 0;');
break;
case 'mul-assign':
$codePrinter->output($variable . ' *= 0;');
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for variable type: int", $statement);
}
break;
case 'int':
case 'uint':
case 'long':
case 'ulong':
switch ($statement['operator']) {
case 'assign':
$codePrinter->output($variable . ' = ' . $resolvedExpr->getCode() . ';');
break;
case 'add-assign':
$codePrinter->output($variable . ' += ' . $resolvedExpr->getCode() . ';');
break;
case 'sub-assign':
$codePrinter->output($variable . ' -= ' . $resolvedExpr->getCode() . ';');
break;
case 'mul-assign':
$codePrinter->output($variable . ' *= ' . $resolvedExpr->getCode() . ';');
break;
case 'div-assign':
$codePrinter->output($variable . ' /= ' . $resolvedExpr->getCode() . ';');
break;
case 'mod-assign':
$codePrinter->output($variable . ' %= ' . $resolvedExpr->getCode() . ';');
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for variable type: int", $statement);
}
break;
case 'char':
case 'uchar':
switch ($statement['operator']) {
case 'assign':
$codePrinter->output($variable . ' = \'' . $resolvedExpr->getCode() . '\';');
break;
case 'add-assign':
$codePrinter->output($variable . ' += \'' . $resolvedExpr->getCode() . '\';');
break;
case 'sub-assign':
$codePrinter->output($variable . ' -= \'' . $resolvedExpr->getCode() . '\';');
break;
case 'mul-assign':
//.........这里部分代码省略.........
示例6: assign
/**
* Compiles foo[] = {expr}
*
* @param $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param $statement
* @throws CompilerException
*/
public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
if ($symbolVariable->isReadOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
}
if ($symbolVariable->isLocalOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
}
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
}
if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'array'))) {
$compilationContext->logger->warning('Possible attempt to append elements on a non-array dynamic variable', 'non-array-append', $statement);
}
$codePrinter = $compilationContext->codePrinter;
$compilationContext->headersManager->add('kernel/array');
$type = $symbolVariable->getType();
switch ($type) {
case 'variable':
switch ($resolvedExpr->getType()) {
case 'null':
$codePrinter->output('zephir_array_append(&' . $variable . ', ZEPHIR_GLOBAL(global_null), PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
break;
case 'int':
case 'uint':
case 'long':
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_LONG(' . $symbolVariable->getName() . ', ' . $resolvedExpr->getCode() . ');');
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
$symbolVariable->setIdle(true);
break;
case 'double':
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_DOUBLE(' . $symbolVariable->getName() . ', ' . $resolvedExpr->getCode() . ');');
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
$symbolVariable->setIdle(true);
break;
case 'bool':
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_BOOL(' . $symbolVariable->getName() . ', ' . $resolvedExpr->getBooleanCode() . ');');
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
$symbolVariable->setIdle(true);
break;
case 'ulong':
case 'string':
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_STRING(' . $symbolVariable->getName() . ', "' . Utils::addSlashes($resolvedExpr->getCode(), true) . '", 1);');
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
$symbolVariable->setIdle(true);
break;
case 'array':
$exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $exprVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
break;
case 'variable':
$exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
switch ($exprVariable->getType()) {
case 'int':
case 'uint':
case 'long':
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_LONG(' . $symbolVariable->getName() . ', ' . $exprVariable->getName() . ');');
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
$symbolVariable->setIdle(true);
break;
case 'double':
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_DOUBLE(' . $symbolVariable->getName() . ', ' . $exprVariable->getName() . ');');
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
$symbolVariable->setIdle(true);
break;
case 'bool':
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_BOOL(' . $symbolVariable->getName() . ', ' . $exprVariable->getName() . ');');
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
$symbolVariable->setIdle(true);
break;
case 'variable':
case 'string':
case 'array':
$codePrinter->output('zephir_array_append(&' . $variable . ', ' . $exprVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
break;
default:
throw new CompilerException("Unknown type " . $exprVariable->getType(), $statement);
}
break;
default:
//.........这里部分代码省略.........
示例7: assign
/**
* Compiles foo[] = {expr}
*
* @param $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param $statement
* @throws CompilerException
*/
public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
if ($symbolVariable->isReadOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
}
if ($symbolVariable->isLocalOnly()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
}
/**
* Only dynamic variables and arrays can be used as arrays
*/
if ($symbolVariable->isNotVariableAndArray()) {
throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as an array", $statement);
}
if ($symbolVariable->getType() == 'variable') {
if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'array'))) {
$compilationContext->logger->warning('Possible attempt to append elements on a non-array dynamic variable', 'non-array-append', $statement);
}
}
$codePrinter = $compilationContext->codePrinter;
$compilationContext->headersManager->add('kernel/array');
$type = $symbolVariable->getType();
switch ($type) {
case 'array':
case 'variable':
switch ($resolvedExpr->getType()) {
case 'null':
$compilationContext->backend->addArrayEntry($symbolVariable, null, 'null', $compilationContext, $statement);
break;
case 'int':
case 'uint':
case 'long':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$compilationContext->backend->assignLong($tempVariable, $resolvedExpr->getCode(), $compilationContext);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
$tempVariable->setIdle(true);
break;
case 'double':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$compilationContext->backend->assignDouble($tempVariable, $resolvedExpr->getCode(), $compilationContext);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
$tempVariable->setIdle(true);
break;
case 'bool':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$compilationContext->backend->assignBool($tempVariable, $resolvedExpr->getBooleanCode(), $compilationContext);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
$tempVariable->setIdle(true);
break;
case 'ulong':
case 'string':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$compilationContext->backend->assignString($tempVariable, $resolvedExpr->getBooleanCode(), $compilationContext);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
$tempVariable->setIdle(true);
break;
case 'array':
$exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $exprVariable, $compilationContext, $statement);
break;
case 'variable':
$exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
switch ($exprVariable->getType()) {
case 'int':
case 'uint':
case 'long':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$compilationContext->backend->assignLong($tempVariable, $exprVariable, $compilationContext);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
$tempVariable->setIdle(true);
break;
case 'double':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$compilationContext->backend->assignDouble($tempVariable, $exprVariable, $compilationContext);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
$tempVariable->setIdle(true);
break;
case 'bool':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$compilationContext->backend->assignBool($tempVariable, $exprVariable, $compilationContext);
$compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
$tempVariable->setIdle(true);
break;
case 'variable':
case 'string':
case 'array':
$compilationContext->backend->addArrayEntry($symbolVariable, null, $exprVariable, $compilationContext, $statement);
//.........这里部分代码省略.........