Jump to content

[SOLVED] classes and objects


Cardale

Recommended Posts

So say for instance I had a function like this

 

<?php
function test()
{
    static $a = 0;
    echo $a;
    $a++;
}
?>

 

I could call this function in one page and it would set its value to 1 and then have a link to the next page which calls the function and it would display 2?

I tested the function out using three separate pages.  One for the class then another to set the value of e to 5 then the third file to get the value of e and it was still 0..I included the class in test2 and test3 pages.

 

Is this not what you meant?

You need to use sessions or a database/flat file to continue using a value across multiple scripts.

 

Static reads as following:

Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).

I guess I need to just give up.  I have been trying to figure out a way to catch a error and have it sent to another page without POST or GET methods.  I save the error in a flat file didn't want to read that and wanted to avoid using a database, but I guess whats the difference in this instance.  It would make things a lot simpler.

 

should I use sessions for something like this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.