note 106178 added to language.variables.scope

From: Date: Mon, 17 Oct 2011 09:04:36 +0000
Subject: note 106178 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-183917@lists.php.net to get a copy of this message
It can be nice to use static variables in class member functions. This avoids a 'class global' like $this->template. Also, I like the system of get and set using the same function. <?php class my_page { public function template($name=null) { static $template = 'templates/page.html'; if ($name) $template = "templates/{$name}.html"; else return $template; } } $p = new my_page; $p->template('product'); include $p->template; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 94.194.32.199 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/106178 Del: integrated -- https://master.php.net/note/delete/106178/integrated Del: useless -- https://master.php.net/note/delete/106178/useless Del: bad code -- https://master.php.net/note/delete/106178/bad+code Del: spam -- https://master.php.net/note/delete/106178/spam Del: non-english -- https://master.php.net/note/delete/106178/non-english Del: in docs -- https://master.php.net/note/delete/106178/in+docs Del: other reasons-- https://master.php.net/note/delete/106178 Reject -- https://master.php.net/note/reject/106178 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183917) next »