# Static class variables and $this

- Thread: https://externals.io/message/7786
- Original archive: https://news-web.php.net/php.internals/7786
- Started by zhundiak@comcast.net on 2004-02-12T19:48:50+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #7786 — zhundiak@comcast.net — 2004-02-12T19:48:50+00:00

URL: https://externals.io/message/7786#7786

Can someone point me to some more information on using PHP 5's static class variables?  All I have been able to find is the zend php5 changes page.
Consider:
error_reporting(E_ALL | E_STRICT);
class foo
{
  static $cnt = 0;
  function getCnt1() { return $this->cnt; } // Does not work, undefined variable
  function getCnt2() { return foo:$cnt; }   // Works as expected
}
$obj = new foo();
echo $obj->getCnt1();

It seems that I should be able to access static class variables from inside of created objects using $this.
Tested with php5b3.

---

## #7788 — Andi Gutmans — 2004-02-12T20:31:34+00:00

URL: https://externals.io/message/7786#7788 · In reply to: #7786

Use self::$cnt but internals@ is not meant for PHP questions but for 
discussing development of PHP.

Andi

At 07:48 PM 2/12/2004 +0000, zhundiak@comcast.net wrote:
>Can someone point me to some more information on using PHP 5's static 
>class variables?  All I have been able to find is the zend php5 changes page.
>Consider:
>error_reporting(E_ALL | E_STRICT);
>class foo
>{
>   static $cnt = 0;
>   function getCnt1() { return $this->cnt; } // Does not work, undefined 
> variable
>   function getCnt2() { return foo:$cnt; }   // Works as expected
>}
>$obj = new foo();
>echo $obj->getCnt1();
>
>It seems that I should be able to access static class variables from 
>inside of created objects using $this.
>Tested with php5b3.
