![]() |
Error in my class
I don't know what's wrong. I had this script before, but without classes, and just regular good old PHP style. And it worked fine with my language system.
Basicly, it's just including a language file depending on the value in the cookie set... The language file itself includes a basic array: english.php PHP Code:
PHP Code:
PHP Code:
For example: PHP Code:
PHP Code:
But it's not working, does anyone have any idea how to make a better system perhaps, or how to fix the problem? |
Firstly, please always put quotes around your array keys (
$lang['first_page']). Secondly, when you include the language file the variable is only set within the scope of the getLanguage function and is therefore not available globally. There are various ways to solve your problem depending on precisely how you want to handle things.One solution would be to assign a member variable to the class and then you'd have to access them rather than using a global variable. Alternatively you can just add the line $GLOBALS['lang'] = $lang directly below each of the three include lines. The latter being a hackish and very much frowned upon way of handling things but it would work for you. |
I generally do tend to put quotes around my array keys. But this time I didn't, don't know why.
Anyhow, what do you mean with assigning a member variable? And what do you mean with "hackish" ? :p Thanks for your fast reply! |
A member variable is a variable which belongs to a class. In this case it belongs to the class with the getLanguages/getLanguage methods (function). You declare it at the top of the class (see code example below) and then can assign values to it using the [inline]$this->variable_name[/i] syntax. We'll declare the variable as public because we need access to it from outside the class.
PHP Code:
PHP Code:
$GLOBALS['myvar'] is the same as [inline]$myvar[/i] in the global scope). It's like using global $myvar in PHP4 functions, urgh. |
I get the idea!
But I can't get it to work within my gallery class for some reason.. I do like you said: PHP Code:
PHP Code:
PHP Code:
=/// |
Hm, I noticed that I didn't actually assign $phrases any value.
But I changed it, and it still doesn't work =/ |
| All times are GMT. The time now is 04:23 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0