Hello, i'me having a wierd problems with sessions.
PHP 4.3.3, Register globals is on, and the sessions module is installed.
if i have a page like this:
<?
session_start();
$_SESSION[ 'color' ]="blue";
?>
On the next page i can see that $_SESSION[ 'color' ] is actually equal to
"blue". So i know that my sessions work in global scope.
Now i tried to make a nice little session wrapper to help in the code
development. Using this wrapper, for some odd reason, it doesn't work.
I posted the class after this text for verification. Did i do a stupid
mistake somewhere? OR am i missing something?
Thanks for all your help! Php4evr! :)
----------------
<?php
class SessionWrapper{
function SessionWrapper( $params = array() ){
session_start();
}
/**
* Gets a session variable, for example,
* $session->getValue( "FavoriteColor" ) would return "blue". Objects
are even serialized.
* so you can set a session string, integer, object, array, whatever. It
will be
* serialized by the session API.
*/
function getValue( $varName ){
global $_SESSION;
return $_SESSION[ $varName ];
}
/**
* Sets a session variable, for example,
* $session->setValue( "FavoriteColor", "blue" ) would set the
* "FavoriteColor" session variable to "blue". Be carefull not to write
over eachother's
* session variables.Objects are even serialized.
* so you can set a session string, integer, object, array, whatever. It
will be
* serialized by the session API.
*/
function setValue( $name, $value ){
global $_SESSION;
$_SESSION[ $name ] = $value;
}
} 5 5378
Yoyoma_2: Hello, i'me having a wierd problems with sessions. PHP 4.3.3, Register globals is on, and the sessions module is installed.
Now i tried to make a nice little session wrapper to help in the code development. Using this wrapper, for some odd reason, it doesn't work.
function getValue( $varName ){ global $_SESSION;
$_SESSION is a superglobal, and there is no need for the global statement.
I'm not sure if this is why it doesn't work. But I must say your class looks
completely meaningless to me, what benefit does it provide? Why do you need
it? Why is
$sessionWrapper->setValue('key', 'value');
better than
$_SESSION['key'] = 'value';
?
André Næss
This is under a project for a "Software Engineering" class where we learn
about desing methodologies so i would like to have proper desing. Since the
rest of the app is done in an OO aproach, i think specifing this entity in
its own class is probably a good idea.
You can imagine the day that you want to add extra pre/post operations when
setting sessions, that could be done easily if it waer a class. But if you
simply do $_SESSION[ 'foo' ] =.. Then you can't do that handling.
Same thing for collision or any other extra handling you would want to do,
etc...
That did the trick! THANKS ALOT!!!!
I guess global $foo; if $foo is superglobal created a new variable called
$foo that wasen't instantiated.. Wow..
Here's a beer. |_|D
It's gotta be cause we have the same first name :) (but mine is french hehe)
TTYL!
"André Næss" <an*********************@ifi.uio.no> wrote in message
news:bp**********@maud.ifi.uio.no... Yoyoma_2:
Hello, i'me having a wierd problems with sessions. PHP 4.3.3, Register globals is on, and the sessions module is installed.
Now i tried to make a nice little session wrapper to help in the code development. Using this wrapper, for some odd reason, it doesn't work.
function getValue( $varName ){ global $_SESSION;
$_SESSION is a superglobal, and there is no need for the global statement.
I'm not sure if this is why it doesn't work. But I must say your class
looks completely meaningless to me, what benefit does it provide? Why do you
need it? Why is
$sessionWrapper->setValue('key', 'value');
better than
$_SESSION['key'] = 'value';
?
André Næss
"Yoyoma_2" <Do********@somewhere.ca> schrieb: function getValue( $varName ){ global $_SESSION; return $_SESSION[ $varName ]; }
I dont' really believe that it's the reason for the error, but you
dont't habe to define $_SESSION as global.
Regards,
Matthias
That was the error Thanks!
"Matthias Esken" <mu******************@usenetverwaltung.org> wrote in
message news:bp**********@usenet.esken.de... "Yoyoma_2" <Do********@somewhere.ca> schrieb:
function getValue( $varName ){ global $_SESSION; return $_SESSION[ $varName ]; }
I dont' really believe that it's the reason for the error, but you dont't habe to define $_SESSION as global.
Regards, Matthias
.... as $_SESSION is always global
Savut
"Matthias Esken" <mu******************@usenetverwaltung.org> a écrit dans le
message de news:bp**********@usenet.esken.de... "Yoyoma_2" <Do********@somewhere.ca> schrieb:
function getValue( $varName ){ global $_SESSION; return $_SESSION[ $varName ]; }
I dont' really believe that it's the reason for the error, but you dont't habe to define $_SESSION as global.
Regards, Matthias This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Doug |
last post by:
Say I have a class with a constant in it. I also have a variable in
that class that I would like to set to that constant as the
initialization value. Why doesn't the following work?
class...
|
by: Neil Zanella |
last post by:
Hello,
It seems to me that using too many variables at class scope in C++ (e.g.
private data members) can be just as bad as having a C program with lots
of global variables. This is especially...
|
by: Andy |
last post by:
Someone supposedly knowledgeable tells me that any member function
declared in class scope is automatically inlined. I am a little
skeptical about this claim. Is this true (I know it cannot be ......
|
by: jose luis fernandez diaz |
last post by:
Hi,
I am reading Stroustrup's book 'C++ Programming Language'. In the
10.4.9 section (Nonlocal Store) he says:
"A variable defined outside any function (that is global, namespace,
and class...
|
by: Steven T. Hatton |
last post by:
It was once suggested to me that I could accomplish much the same thing that
modules would accomplish (if C++ had modules) by writing my entire program
- except for main() - inside of a class. ...
|
by: Michael |
last post by:
Hello, I have a newbie question about class scope. I am writting a little
program that will move files to one of two empty folders. I am having a hard
time understanding scope. So this will be a...
|
by: pelleas |
last post by:
Hello to all!
1a. I'm a newbie having trouble accessing a pointer from one .cpp file which is defined within a member function found in a separate .cpp file. I'm looking for a line or two of...
|
by: Steven T. Hatton |
last post by:
If find the following excerpt from the Standard a bit confusing:
<quote>
3.3.6 - Class scope
-1- The following rules describe the scope of names declared in classes.
1) The potential scope...
|
by: AndrewD |
last post by:
Hey C++ folks,
I created this today, just for fun.
You can make object allocation for any class around 6 times faster,
simply by doing the following.
class MyClass : public...
|
by: toton |
last post by:
Hi,
Is it possible to have a class level namespace opening instead of
file level .
Something like this,
I have a long namespace like
namespace com { namespace my_company{ namespace...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |