Classes named Session

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Classes named Session

Post by Charles256 »

does that cause issues in PHP5?because my class called session is suddenly displaying all it's code on the webpage when I upgraded to version 5 :-/
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It souldn't matter. The superglobals are in a different namespace to classes (in PHP5 classes share the namespace with interfaces and that's it AFAIK). Are you sure PHP5 isn't having other issues?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Is it only that class or all of your code?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

have you tried changing the name just to test?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

thanks for the replies and sorry for the long delay. i only work at this job two days a week so it's been a while since I've had access to the source code. Either way...going back we find..
time = time(); $this->startSession(); } /* *
that's the beginning of the output on the page and that goes all the way till the code ends..i will now show relevant code up till that point..

Code: Select all

*
 * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 * Last Updated: August 19, 2004
 */
include("database.php");
include("mailer.php");
include("form.php");

class Session
{
   var $username;     //Username given on sign-up
   var $userid;       //Random value generated on current login
   var $userlevel;    //The level to which the user pertains
   var $time;         //Time user was last active (page loaded)
   var $logged_in;    //True if user is logged in, false otherwise
   var $userinfo = array();  //The array holding all user info
   var $url;          //The page url current being viewed
   var $referrer;     //Last recorded site page viewed
   /**
    * Note: referrer should really only be considered the actual
    * page referrer in process.php, any other time it may be
    * inaccurate.
    */

   /* Class constructor */
   function Session(){
      $this->time=time();
      $this->startSession();
as you can see up until it gets to $this->time it's fine..something about that arrow is <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> it off though....Any more ideas? I've renamed the class..no dice...
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

assuming you have missed it when copying, but just to be on the safe side, the page does start with /* and not just * right?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

I just missed it when copying :-D And I removed all comments before the troubled section..still same error.just spitting the code to the page...I FIGURED IT OUT! mwua ha ha...I noted he was using short tags..so I thought to myself....do I have short tags enabled? no sir I do not. therefore I replaced all short tags with long tags and tada. Heh... Man I feel like an idiot..
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

d11wtq, do you say if an user defined class is named session, it will not be a problem even if there already exists a class with name session used by PHP?

How the distinction is made? I just want to know how are you guys handling namespaces in PHP. I do not think even PHP 5 does have that feature. If I want to create two different classes with the same name, how can I do that if I am not able to use packages which I think is not available in PHP 5.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Namespaces are not available in PHP 5. Supposedly (and the same goes for Unicode), PHP6 will make all our troubles vanish.

Other than that, you just have to be careful when you name classes common names.
Post Reply