create_function

I am having a terrible time getting this to work. Everything works great to create a page but now I am trying to add additional fields $class and $style and they are not being added. I know the $_get is working correctly because I can echo it. Please help me understand why I can pass $function and not $style?

$function = $_GET['function'];
$class = $_GET['class'];
$style = $_GET['style'];
	call_user_func(
					create_function('$section', '
						$page = new Page;
						$page->div($section,$class,$section.".php",$style);
						echo($page->render());'), 
					$function);	

class Page{
	//This array stores each div of HTML code
	var $innerHTML = "";
	function Page(){
		$this->innerHTML .= "<div id='wrapper'>n";
	}
	function div($id, $class, $filename, $style){
		$handle = fopen("templates/$filename", "r") or 
	         die("Cannot open template file "$filename".");
		$content = fread($handle,filesize("templates/".$filename));
		fclose($handle);
		$html = "<div id='".$id."' class='".$class."' style='".$style."'>n".$content."</div>n";
		$this->innerHTML .= $html;
	}
	function headerImage($imageName){
		$this->div("headerImage","", "headerImage.php");
	}
	function render(){
		$this->innerHTML .= "</div>";
		return $this->innerHTML;
	}
}

Why are you using a construction like call_user_func(create_function(…))? Is that really necessary?

Sponsor our Newsletter | Privacy Policy | Terms of Service