There is a file myclass.php:
<?php
class Myclass {
public static function Fun1() {
}
}
and i try to make an own framework where to use a code generation:
$class = "MyClass";
$function = "Fun1";
$fname = "myclass.php"
if (class_exists($class) && !method_exists($class, $functionName)) {
$current = file_get_contents($fname);
if ($current) {
$strIndex = strlen($current);
while ($strIndex-- && $current[$strIndex] != "}");//removing the last '}'
$current = substr($current, 0, $strIndex);
$current .= "\tpublic static function $functionName() {\n";//there inserting the new function
$current .= "\n";
$current .= "\t}\n";
$current .= "}\n";
$current .= "\n";
file_put_contents($fname, $current);
require $fname;//I load the file again, but how to redeclare the class?
}
}
.. and i get a message: Fatal error: Cannot redeclare class MyClass in C:\xampp\htdocs\myproj\index.php on line 12. Thank you.