note 106178 modified in language.variables.scope by danbrown
| From: | danbrown@php.net | Date: | Mon, 17 Oct 2011 16:21:02 +0000 |
| Subject: | note 106178 modified in language.variables.scope by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183925@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();
?>
--was--
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;
?>
http://php.net/manual/en/language.variables.scope.php