Parse error: syntax error, unexpected token "public", expecting end of file in /var/www/html/PHP-and-MySQL-Web-Development/Chapter06/overloading-methods-with-call-pag-188/overloading-methods-with-call.php on line 2

public function __call($method,$p){
    if($method =="display"){
        if(is_object($p[0])){
            $this->displayObject($p[0]);
        } else if(is_array($p[0])){
            $this->displayArray($p[0]);
        } else {
            $this->displayScalar($p[0]);
        }
    }
}
$ov = new overload;
$ov->display(array(1,2,3));
$ov->display('cat');

    The function needs to be inside of a class definition (i.e. making it a "method" within that class). Presumably it would be in the overload class in this case, since that is what you are instantiating via the new call after that?

      Write a Reply...