Page 3 of 3

Posted: Tue Aug 15, 2006 5:34 pm
by Oren
feyd wrote:The function works perfectly fine for my needs. .. not that I ever use it.
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?

Posted: Tue Aug 15, 2006 5:38 pm
by feyd
As far as I see, the manual describes exactly what it does, correctly. I can understand the function's name being slightly confusing though. You could always alias it to get_scope_vars() maybe, or just accept that only in the global scope will you see the superglobals and move on.

:)

Posted: Tue Aug 15, 2006 5:41 pm
by Luke
I don't see anything wrong with the manual either.

Posted: Tue Aug 15, 2006 5:45 pm
by Oren
feyd wrote:or just accept that only in the global scope will you see the superglobals and move on.

:)
That's totally fine. Actually, that's exactly what I needed - I don't need the superglobals :P

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';
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?

Thanks :wink:

Posted: Tue Aug 15, 2006 5:51 pm
by Christopher
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. :D
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.
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?
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.

Posted: Tue Aug 15, 2006 6:07 pm
by feyd
Oren wrote:

Code: Select all

<?php

	$some_config_value = 'whatever';
	$some_config_value2 = 'whatever2';
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?
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.
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.
Correct on both counts. .. not that I was expecting you to be wrong. Image

Posted: Wed Aug 16, 2006 2:17 am
by Oren
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() ?

Posted: Wed Aug 16, 2006 7:49 am
by feyd
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() ?
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.

Posted: Wed Aug 16, 2006 9:24 am
by Oren
Ok, I'll put more thought into it once I write a real application. Right now, I'm just doing this to improve my OOP knowledge and working with patterns.

Any good OOP books (PHP5) by the way? New books please, not books from 2004 even if they are great.

Posted: Wed Aug 16, 2006 9:32 am
by feyd
If you want to improve your OOP knowledge, I'd use a Value Pattern, or similar.

Posted: Wed Aug 16, 2006 9:39 am
by Oren
feyd wrote:If you want to improve your OOP knowledge, I'd use a Value Pattern, or similar.
I'd like to master the basics first :P If you remember from one of my posts, I mentioned that I learned OOP from a tutorial on the Zend site... Now I want to learn it from the beginning as it should be, and not from online tutorials.
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 :P