I am working on an object that allows us to modify PHP files containing PHP objects. (In particular, these are Doctrine entity files that we must modify.)
In any case, without the boring details, what happens here is happening. First, I find the location of the class file and TURN ON it. Then I instantiate the class and the class reflector using the code below. As you can see, when I instantiate an object and a reflector, I also call a method to load the text of the class from disk into a string and another method to split this string into an array of rows.
public function loadClass()
if(!class_exists($this->class_name)) {
$this->error = "Class name: '$this->class_name' was not found.";}
else {
$this->oClass = new $this->class_name;
$this->oRClass = new \ReflectionClass($this->oClass);
$this->source_file = $this->oRClass->getFileName();
$this->error = "";
$this->class_namespace = $this->oRClass->getNamespaceName();
$this->getClassText();
$this->getClassArray();
}
}
"deleteMethod()", PHP- : $this->deleteMethod("badMethod");. , , , PHP 'loadClass()', , . "deleteMethod()".
$oMethod = $this->oRClass->getMethod($meth_name);
$oMethod->setAccessible(true);
$start_line = $oMethod->getStartLine() -1;
$length = $oMethod->getEndLine() - $start_line + 1
array_splice($this->class_array, $start_line, $length);
$this->class_text = implode("\n", $this->class_array);
$this->saveClassText();
$this->loadClass();
, , , -. $this->deleteMethod("anotherBadMethod");, , . , , / , PHP OLD . , , - , . , , , loadClass(). , NULL, .
, PHP . , , getFileName(); , , .
Soooo.... PHP , ? , ? "undefine", ? .