I want to add plug-in functionality to a class. That is, I want the class to have a function called load_plugin($file) that includes the $file so that all code inside $file is now functions of the class.

Sounds weird? Let me explain. I have 2 files:

sample-plugin.php
PHP Code:
<?php
function new_class_function() {
   
$this->name 'Class Name 2';
}

new_class_function();
?>
myclass.php
PHP Code:
<?php
class cms {
   
$var name;

   function 
cms() {
      
$this->name 'class name';
   }

   function 
load_plugin($file) {
      include 
$file;
   }
}


$cms = new cms();
echo 
$cms->name;
$cms->load_plugin('sample-plugin.php');
echo 
'<br>'.$cms->name;
?>
However, this does not work as PHP says that $this->name does not exists inside new_class_function() (quite obvious if you consider the scope of the function inside the class)

How can I do that? I know runkit and classkit can do this but those are modules not bundled with PHP.

Any questions?