Ok, so the static members die on page reload.
Then I must say it works fine.
It's indeed a 'poor man's caching system' :(
On Thu, 26 Oct 2006 10:35:22 -0500
Bryan Alsdorf <bryan mysql.com> wrote:
> Hi Jostein, is this a problem with the specific code
below or all
> cases where static is used?
>
> In my test on PHP 5, static variables work as expected.
>
> Class monkey {
> function testStatic($foo)
> {
> static $blah;
>
> if (isset($blah[$foo])) {
> return "Static variable used<br
/>";
> }
> $blah[$foo] = 'FOOO';
> return 'No static<br />';
>
> }
> }
>
> echo monkey::testStatic(1);
> echo monkey::testStatic(1);
>
> echo "Version: " . PHP_VERSION;
>
> Outputs:
> No static
> Static variable used
> Version: 5.1.2
>
> /bryan
>
> Jostein Martinsen wrote:
> > Hi
> > I am using PHP5 and the static members/variables
doesn't seem to
> > stick. PHP5 doesn't seem to care about the static
keyword. It would
> > be nice to get this working.
> >
> > For example: In the code below, I never get a
return before the
> > print-line.
> >
> > function getSelectedColumns($prj_id, $page)
> > {
> > static $returns;
> >
> > // poor man's caching system
> > if (!empty($returns[$prj_id][$page]))
> > return $returns[$prj_id][$page];
> >
> > print("I always get here!");
> > ...
> >
$returns[$prj_id][$page][$field_name]="Jello";
> > ...
> > }
> >
> >
> >
+-------------------------------------------------------+
> > Jostein Martinsen
> > System developer, Redpill AB
> > Tel: 0734-241 475, 054-4005 142
> > E-mail: jostein.martinsen redpill.se
> >
> >
>
+-------------------------------------------------------+
Jostein Martinsen
System developer, Redpill AB
Tel: 0734-241 475, 054-4005 142
E-mail: jostein.martinsen redpill.se
--
Eventum Users Mailing List
For list archives: http://lists.mys
ql.com/eventum-users
To unsubscribe: http:
//lists.mysql.com/eventum-users?unsub=bond yahoo.com
|