skip to content »

Php updating a static variable

php updating a static variable-75

Note: When you assign a text value to a variable, put quotes around the value.

php updating a static variable-50

Solution 2: Turn static $a on class A into an array, use classnames of subclasses as indeces.(namely because the code is modulized, and 'safeinclude' is meant to be generic)My solution: Thus, to make all my global variables available to the files included with my safeinclude function, I had to add the following code to my safeinclude function (before variables are used or file is included)In the above, 'exists' & 'file' are determined in the pre-processing.File is the full server path to the file, and exists is set to true if the file exists. In my own, I added additional optional parameters so that I can call safeinclude to see if a file exists without actually including it (to take advantage of my path/etc preprocessing, verses just calling the file exists function).I'm certain there's a far more elegant solution than setting a bunch of global vars to then just hardcode references to them in a nav elsewhere While I strongly advise against this, and it will not speed things up, your usage is incorrect.When you try to use a global you must specify the global keyword first. Word Press already attempts to cache these things in the object cache.I myself had this gap in my PHP knowledge until recently and had to google to find this out.

I think this page should have a "See also" link to static function variables. careful while calling static constants or methods dynamically with a variable.

I am trying to set up a whole bunch of global variables for the permalinks to categories to be used in various places in my theme.

Why would you not just use 'get_cat_ID( **** )' where ever you planned to use the global variable.

I created a function (safeinclude), which I use to include files; it does processing before the file is actually included (determine full path, check it exists, etc).

Problem: Because the include was occurring inside the function, all of the variables inside the included file were inheriting the variable scope of the function; since the included files may or may not require global variables that are declared else where, it creates a problem.

PHP automatically converts the variable to the correct data type, depending on its value.