phpsa icon indicating copy to clipboard operation
phpsa copied to clipboard

Implement support for Unset operator

Open ovr opened this issue 9 years ago • 3 comments

$a = 1;
unset($a);

var_dump($a); // Undefined?

ovr avatar May 30 '16 09:05 ovr

i think unset() is a function and no operator. Maybe we should also add a warning to the (unset) cast since it is not the same as the unset() function. (and the (unset) cast is pretty useless)

ddmler avatar May 30 '16 10:05 ddmler

@ddmler Hey!

Unset can be

  • Operator
unset $a;
  • Function http://php.net/manual/ru/function.unset.php
unset($a):

I created another issue for unset fcall https://github.com/ovr/phpsa/issues/70

ovr avatar May 30 '16 11:05 ovr

So, I am wrong unset is an operator (because it's handled by VM OPCODE) but with function call like syntax

And @nikic's php-parser named it like PhpParser\Node\Stmt\Unset_

From PHP-src I didnt find PHP_FUNCTION(unset) but find statement with opcode Review https://github.com/php/php-src/blob/2ae21abdf7b87ee95d76aca22e787408d7c766cf/Zend/zend_vm_opcodes.c#L99

Seems there are some parts

  • [ ] Unset variable from Context->SymbolTable
  • [ ] Unset referenced variables
  • [ ] Unset for object property
  • [ ] Magic __unset method
  • [ ] Unset for array type

ovr avatar May 30 '16 11:05 ovr