php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18060 request for user defined superglobals
Submitted: 2002-06-29 06:32 UTC Modified: 2002-06-29 10:08 UTC
From: cstdenis at hotmail dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.2.1 OS: any
Private report: No CVE-ID: None
 [2002-06-29 06:32 UTC] cstdenis at hotmail dot com
I am requesting a feature of user defined 'superglobal' varables. This would be handy for a varable that is set in the header containing somthing like username or access level that is used throughout a script.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-29 10:08 UTC] rasmus@php.net
Won't happen.  You can already set variables that are accessible everywhere by specifying you want to access a global variable via "global $user" or $GLOBALS['user'].  The whole point is to prevent nasty global variable side-effects that other languages are prone to.
 [2012-09-12 00:59 UTC] markus dot behm at gmail dot com
There are so many ways to shoot yourself in the foot in php if used wrongly that  
I feel the response given here is a bit moot point. Take ruby for example, yes 
you can totally fuck it up if you do stupid things but is it prone to the 
problems? No.

I've created a very powerful database abstraction based on models and since you 
can't define constant instances of classes (eg. Account), being able to create 
superglobals (eg. $Account) would be the next closest thing but no.

Because of these instead of this

$events = Contacts->join('accounts', 'events')->where(
  Event['start_date']->gteq($start_date),
  Event['end_date']->lteq($end_date),
  Event['type']->eq($type),
  Contact['owner_id']->eq($current_user->id)
)->project('firstname', 'lastname', Account['accountname'], Event['subject']);

You have to do something like this (closest I have come so far)

$events = M::$Contacts->join('accounts', 'events')->where(
  M::$Event['start_date']->gteq($start_date),
  M::$Event['end_date']->lteq($end_date),
  M::$Event['type']->eq($type),
  M::$Contact['owner_id']->eq($current_user->id)
)->project('firstname', 'lastname', M::$Account['accountname'], 
$::$Event['subject']);

Not that much worse but it compunds over time.

Maybe the only reason why such feature doesn't exist is because somebody fucked 
up with certain other language magic in the first place.
 [2012-09-12 01:04 UTC] markus dot behm at gmail dot com
And yes I do know that I could fix that with one line of code (global $Contact, 
$Event, $Account) but updating that line every time you need a model is a real 
pita.

Also typing M::$Account is quite a bit harder than Account or $Account ;)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC