<?php

$data = <<<'DATA'

<?php

// base class with member properties and methods
class Vegetable {

   var $edible;
   var $color;

   function Vegetable($edible, $color="green")
   {
       $this->edible = $edible;
       $this->color = $color;
   }

   function is_edible()
   {
       return $this->edible;
   }

   function what_color()
   {
       return $this->color;
   }

} // end of class Vegetable

// extends the base class
class Spinach extends Vegetable {

   var $cooked = false;

   function Spinach()
   {
       parent::__construct(true, "green");
   }

   function cook_it()
   {
       $this->cooked = true;
   }

   function is_cooked()
   {
       return $this->cooked;
   }

} // end of class Spinach

?>
DATA;


$class_regex = '~
					^\s*class\s+
					(?P<class>\S+)[^{}]+(\{
					(?:[^{}]*|(?2))*
					\})~mx';

$data = preg_replace_callback($class_regex, 
	function($match) {
		$function_regex = '~function\s+\K'.$match['class'].'~';
		return preg_replace($function_regex, '__construct', $match[0]);
	},
	$data);

echo $data;
?>
