Oh no, it works fine for me too... But yet, after trying arborint's example, it seems that the function doesn't work as it should work according to the manual, am I right in that part?feyd wrote:The function works perfectly fine for my needs. .. not that I ever use it.
get_defined_vars doesn't return superglobals when...
Moderator: General Moderators
That's totally fine. Actually, that's exactly what I needed - I don't need the superglobalsfeyd wrote:or just accept that only in the global scope will you see the superglobals and move on.
I was working on a settings class and that's why I used get_defined_vars.
I have a normal settings file like this one:
Code: Select all
<?php
$some_config_value = 'whatever';
$some_config_value2 = 'whatever2';Thanks
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I believe that "var $myvar;" is considered a declaration and "var $myvar = 1;" is considered a definintion, when the two terms are distinguished -- mostly the mean the same thing.feyd wrote:There's a distinction in programming languages between "declared" and "defined" however. I would probably prefer "instantiated." Although I can't expect most people to spell that one right.
It seem to work accoring to the manual to me, it is just not completely consistent for practical reasons -- external and internal. Many functions works as they should, though not completely consistently, and thank goodness for that.Oren wrote:Oh no, it works fine for me too... But yet, after trying arborint's example, it seems that the function doesn't work as it should work according to the manual, am I right in that part?
(#10850)
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
When doing configurations with php files, I usually put all the variables into an array to begin with. Similar to how phpBB stores the language strings in $lang. There are other instances where I've stored them in an value object.Oren wrote:Do you know of any better way to read these values into an array where the variable names would be the keys and the variable contents would be the values?Code: Select all
<?php $some_config_value = 'whatever'; $some_config_value2 = 'whatever2';
Correct on both counts. .. not that I was expecting you to be wrong.arborint wrote:I believe that "var $myvar;" is considered a declaration and "var $myvar = 1;" is considered a definintion, when the two terms are distinguished -- mostly the mean the same thing.

- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
If you need to allow people to hand edit the config and not know PHP, I wouldn't use a PHP script for the configuration then. Likely, it would be an INI, or not give them direct editing control at all.Oren wrote:That's nice and cool, but I want it to be as simple as possible for people who don't know PHP to fill it out. I may consider using an array though, thanks for the suggestion.
Any issues you can think of with my way - using get_defined_vars() ?
I'd like to master the basics firstfeyd wrote:If you want to improve your OOP knowledge, I'd use a Value Pattern, or similar.
I know it's kinda strange, but even though I'm an OOP noob, I still learn about advanced things like patterns. Advanced relative to my OOP knowledge