Re: How to declare a static object in PHP?
- From: "danielMitD@xxxxxxxxxxxxxx" <danielMitD@xxxxxxxxxxxxxx>
- Date: Fri, 30 May 2008 00:25:17 -0700 (PDT)
On May 23, 4:23 pm, ngxfer...@xxxxxxxxx wrote:
Hi experts,
I am new to PHP, I have a HashMap class and want to declare as static
in my other class,
class web
{
public static $map = new HashMap();
}
somehow the compiler is complaining. It only allows me to do the
following:
class web
{
public static $map;
public __construct()
{
map = new HashMap();
}
}
but I don't want this, sorry for my stupid questions, i was coming
from C++ and Java background, so I am not quite familar with the
syntax in PHP.
Thanks alot
Best regards
ferdinand
just two easy changes:
class web
{
public static $map;
public function __construct()
{
self::$map = new HashMap();
}
}
- you have to access static object properties via self:: not via $this-
- and the construct needs the function keyword, like any other
function in php
kind regards
daniel
.
- References:
- How to declare a static object in PHP?
- From: ngxfer001
- How to declare a static object in PHP?
- Prev by Date: Re: gettext() function
- Next by Date: Re: PHP Tutorials
- Previous by thread: How to declare a static object in PHP?
- Next by thread: Sending Email
- Index(es):
Relevant Pages
|