[PHP problem] Calling an object's function with parameters

09/10/2013 15:13 BigM'#1
Hey guys,

recently I got a problem with PHP on which I haven't found a solution yet. I'm calling a function out of a object, but there seems to be a problem regarding the parameters.

Object (very simplyfied):

PHP Code:
class HP{
    function 
preload_async($folders){
    
var_dump($folders);
    }

than, later on:

PHP Code:
$HP = new HP
if I want to call the function now in a part of my document:

PHP Code:
<?=$HP->preload_async(array('slide','store'))?>
the dump just throws out stuff like this:

PHP Code:
array(1) {
    [
0]=>
    
string(0""

Anyone got an idea why it isn't working? I'm quite common with PHP and did a lot of similar stuff and that's why I'm wondering this code won't work.

Thanks for you advise!
09/10/2013 16:39 Chrisomator#2
Try to define the function's parameter as an array as default.

PHP Code:
class HP
    function 
preload_async($folders = array()){ 
    
var_dump($folders); 
    } 

09/10/2013 16:53 BigM'#3
Quote:
Originally Posted by Chrisomator View Post
Try to define the function's parameter as an array as default.

PHP Code:
class HP
    function 
preload_async($folders = array()){ 
    
var_dump($folders); 
    } 

I tried this one as well, without any effect. To be precise, I firstly wondered about an error regarding a predefined parameter ($folders, $foo="bar") which weren't set correctly before discovering neither the first one is functionable.
09/10/2013 17:21 Sedrika#4
PHP Code:
class HP{
    function preload_async($folders){
    return var_dump($folders);
    }
}  
$HP = new HP();

//....

<?php
$HP
->preload_async(array('slide','store'));
?>
This should help you a bit.
09/10/2013 22:36 BigM'#5
Thanks Sedrika for your try to help me, but badly it didn't work. I'm totally confused about that, because I did (like I mentioned before) really a lot of PHP codes during the last years.. and the code above seems clearly having to work!
09/10/2013 22:40 Synatex#6
Show us the code or do not. But please stop posting those half-baked code parts which do absolutely say nothing since there can still be a mistake within your main code.

I bet no one is here to steal or do some other curious stuff with it. However, we're no projectionists so we won't be able to help you as long as you do not provide us with some code which is getting used and the actual PHP error.
09/10/2013 23:28 BigM'#7
It wasn't a question of code being stolen or copied, the code is simply placed in three diferent files and positions(index, functions & home .php) which caused me to serve the code in parts.
Here is a spoiler showing the whole function, the rest is the same as well in mine.


The function was originally coded to preload specific folders of images asyncronous or directly. I know it's not a pretty way to do this, but the explained error occured during my work to rewrite it.
09/11/2013 00:09 Synatex#8
Still, as said in the topic above, post the whole code or do not. This piece of code does say nothing. I've replicated your top example with just like any common combination you can find and each one worked...

So I just apply to you again, please post the whole code including the object.

... and even if there are 3 files, why dont you copy the contents of those 3 into this topic? We're trying to help and all you provide is some basic structure, no reliable example. How should we help there..