I was doing some tweaking of gallery, however not being too adept in php, Im having problems returning an array of values from a custom function. I know how to do this in C, however php doesnt seem to have an equivalent *pointer. What's the best way to do this?
Thanks
Posts: 3474
PHP is very loosely typed. Arrays, strings, ints, typing is mostly transparent. If your variable is an array, then $variable is in fact a pointer (okay, it's really a symbol reference) to your array construct, and it is dereferencable. Just like in C, where array[x] is the same as (type) *(&array+x*sizeof(type)), in PHP $array[$x] gives you your value, though unlike C, you can't actually look at the pointer and see what memory address it maps to (because it's not a pointer, but a "name").
will print out
Does that answer your question? Probably not... so post back w/more details.
-Beckett (
)
Posts: 26
I better be more explicit.
Im sorry I dont have the code in front of me since Im at work and the exact code is at home, however Ill do my best to improvise.
I basically have something like this:
In the above code if the count of $matches is 6 (for example), the only thing I get back is $matches[5] -- and hence the count of dir_list always equals 1. I want the the whole $matches array return, not just the last value.
PS One last thing - kind of unrelated. I included at the top the file defaults.inc. As you can imagine this basically is a php file with stated defaults, such as $home='http://abc.com'; $main_dir='c:\\temp'; etc.
The problem is that these variables are not seen inside the scope of the class. I tried moving the include statement into the constructor function of the class, however once again, these variables were only available inside the scope of the constructor, not in the other member functions. What is the best way to make the default variables available to all class member functions (using an include statement), without having to explicitly set each variable in a constructor function for example? Again I thought it would be great to place all the defaults located in the default.inc file, inside a default array. Inside the class, I could have a class member variable declared as $def, and then call a specific function located inside default.inc that would set $def=$default_array. Again however this would require returning an entire array from a function.
Posts: 3474
Well, if you have six matches, then the returned array should contain six elements, 0-->5. Can you debug the exact returned array?
You're correct about the included variables being out of scope, since they're not declared as globals. Remember... to preserve the sense of a class entity, all class variables should be declared inside the class itself. So you should declare them inside the class, outside of the constructor. Then the constructor should initialize them individually. You could bunch the class variables together into an array, and pass the array out to another function, if you like, but that sounds more complicated. (Though you could pass the array by reference (&$array), so you're not copying huge amounts of data around the place). Global variables you should consider making truly global. Make sure you're declaring all of your variables where it makes most sense.
Since this isn't really a PHP help forum, you'll probably have more success over on one of the PHP help sites, or on IRC (#php on freenode.net). We try to stick to Gallery-related stuff over here.
-Beckett (
)