|
Posted by Kimmo Laine on 11/30/06 10:42
"Steve JORDI" <steveK_I_L_LSPAMjordi@hotmail.com> wrote in message
news:o08tm2to3vt8bkkka03mqot1dbo2t83jhc@4ax.com...
> Hi,
> I'm trying to implement a singleton in PHP4 but it doesn't seem to
> work. The object is recreated each time I call it.
PHP4 is not the best platform for OOP. PHP5 has much more sophisticated
object handling.
> The goal of the class is to keep a variable up to date.
> It's used to display a database content, 25 rows at a time.
> The singleton keeps track of the current starting row and
> increases it or decreases it by 25 depending on the user action
> (pressing a Next or Prev button).
> Those buttons are submit buttons calling the current form itself.
>
> But each time I re-enter that form, the singleton variable is created
> again and therefore the currentRow variable reinitilize
I'm guessing you have a C++ or Java background. The request/response
architecture is quite different from a desktop application. A variable will
not be available thru two different page calls unless it's stored as a
session variable. Otherwise, each page call should be concidered as
restarting an application and at the end of the page all variables are
destroyed except for session variables.
First I encourage you to go for php version 5, you'll get much more out of
the classes and objects. Next thing you should do is learn how sessions
work. And then finally, check out the singleton example at php.net:
http://www.php.net/manual/en/language.oop5.patterns.php
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|