Ir ao conteúdo
  • Cadastre-se

Problema com Singleton


Posts recomendados

Bom Dia Pessoal,

 

Tenho o seguinte código:

<?php    class generateHTML {                private static $instance;        private $title;        private $head;        private $page;        private $header;        private $footer;        private $article;        private function __construct() {                        $this->title = "Corollarium";        }                public static function getInstance() {                        if(!isset(self::$instance)) {                                $c = __CLASS__;                self::$instance = new $c;            }                        return self::$instance;        }        public static function setTitle($title) {                        $this->title = $title;        }                public static function getTitle() {                        return $this->title;        }                public static function setHead($head) {                        $this->head = $head;        }                public static function getHead() {                        return $this->head;        }                public static function setHeader($header) {                        $this->header = "<header>" . $header . "</header>";        }        public static function getHeader() {                        return $this->header;        }                public static function setFooter($footer) {                        $this->footer = "<footer>" . $footer . "</footer>";        }                public static function getFooter() {                        return $this->footer;        }                public static function setArticle($article) {                        $this->article = "<article>" . $article . "</article>";        }                public static function getArticle() {                        return $this->article;        }        /*public static function render() {                        $page = "<html>" . "<head>" . self::getHead() . "<title>" . self::getTitle() . "</title>" . "</head>";            $page = $page . "<body>" . $this->getHeader() . $this->getArticle() . $this->getFooter() . "</body>";            $page = $page . "</html>";                        return $page;        }*/    }        $exemplo = generateHTML::getInstance();    //print $exemplo->render();    $exemplo->setHead("adjflaskjfd");    //var_dump($exemplo === generateHTML::getInstance());?>

Mas quando executo $exemplo->setHead("adjflaskjfd"); ele gera o erro da figura em anexo.

 

Alguém poderia me ajudar?

 

 

post-620290-0-42541700-1437726502_thumb.

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...