1

I want to create a file-static variable in PHP. How can I do this or what should I use instead?

Edit:

I'm basically wanting to create a file-scope static variable, similar to what is available in C/C++.

EmpireJones
  • 2,936
  • 4
  • 29
  • 43
  • Yeah, it sounds like a variable that is only global for a single file. For what purpose do you want this? – theazureshadow Nov 12 '10 at 05:41
  • I mean, if it's *really* necessary you could create some sort of class with a static variable that is an array based on the filename (passed in with `__FILE__`, but I can't see that actually being useful. Maybe for some weird debug utility? – theazureshadow Nov 12 '10 at 05:43

2 Answers2

0

You can take a look at namespaces. Available only in PHP >=5.3 http://www.php.net/manual/en/language.namespaces.rationale.php

Sébastien VINCENT
  • 1,096
  • 6
  • 11
  • PHP namespaces can not contain variables according to the answers here: http://stackoverflow.com/questions/5287315/can-php-namespaces-contain-variables – EmpireJones May 22 '12 at 02:00
0

After further investigation, it seems like the easiest solution is to just use a class which wraps the functions. The only downside is you have to use the prefix when calling: Container::Func(); This could be solved with an additional wrapper for each function, but this isn't as clean of a solution.

EmpireJones
  • 2,936
  • 4
  • 29
  • 43