6

Suppose a PHP script uses methods of class A and then regenerates new source code of class A.

If class A is already declared, does PHP provide a method to undeclare class A so that I may re-require the newly created source of class A?

By 'already declared' I mean, that the source of a class has been parsed, thus the class name is defined and bound to the class definition.

Update 2014-02-22

RunKit does provide the runkit_constant_remove. Without using RunKit, there doesn't seem to be a method to undeclared / undefine a class.

SteAp
  • 11,853
  • 10
  • 53
  • 88
  • 1) Generates through Reflection API? 2) What do you mean already defined? Included? 3) (Proposal) Place new code in different location and require it from there. If using namespace just change it from one that uses original class A. – Eugene Feb 22 '14 at 03:27

1 Answers1

6

This is not possible in PHP. There are extensions for defining methods, extending classes at runtime, etc, but none for completely undefining a class so you may redefine it.

Brandon
  • 16,382
  • 12
  • 55
  • 88