|
You last visited: Today at 18:08
Advertisement
[PHP problem] Calling an object's function with parameters
Discussion on [PHP problem] Calling an object's function with parameters within the Web Development forum part of the Coders Den category.
09/10/2013, 15:13
|
#1
|
elite*gold: 11
Join Date: Nov 2009
Posts: 1,247
Received Thanks: 363
|
[PHP problem] Calling an object's function with parameters
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:
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
|
#2
|
elite*gold: 0
Join Date: Jan 2010
Posts: 109
Received Thanks: 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
|
#3
|
elite*gold: 11
Join Date: Nov 2009
Posts: 1,247
Received Thanks: 363
|
Quote:
Originally Posted by Chrisomator
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
|
#4
|
elite*gold: 18
Join Date: Sep 2009
Posts: 20,177
Received Thanks: 14,471
|
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
|
#5
|
elite*gold: 11
Join Date: Nov 2009
Posts: 1,247
Received Thanks: 363
|
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
|
#6
|
elite*gold: 25
Join Date: Apr 2010
Posts: 1,009
Received Thanks: 316
|
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
|
#7
|
elite*gold: 11
Join Date: Nov 2009
Posts: 1,247
Received Thanks: 363
|
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.
PHP Code:
function preload_async($folders, $async = true){ return var_dump($folders); ($async)?($as_string="async='async'"):($as_string="$async"); $standard = array('','store','detailed','cart','blog', 'products'); ($async)?($folders = array_merge($folders, $standard)):(1); $imgs=array(); foreach ($folders as $folder) { if($folder == 'products'){ $i = 1; do{ if(is_dir("./images/$folder/$i")){ $n_imgs= $this->prel_imgs("$folder/$i"); foreach ($n_imgs as $n_img) { array_push($imgs, $n_img); } }else{ break; } $i++; }while($i!=0); }else{ $imgs= array_merge($imgs, $this->prel_imgs($folder)); } } return("<script type='text/javascript' $as_string> function preload_async(){ arr = ". str_replace("\/", "/", json_encode($imgs))."; for(var img in arr){ var someimg = new Image(); someimg.src = arr[img]; } } preload_async(); </script>"); }
Note: The second parameter ($asnc) has been removed during my test phase.
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
|
#8
|
elite*gold: 25
Join Date: Apr 2010
Posts: 1,009
Received Thanks: 316
|
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..
|
|
|
|
Similar Threads
|
Help me with calling a game function in DLL (crash)
05/12/2013 - General Coding - 1 Replies
Heya,
Gonna make it short, my game crashes when i call my function, the address of the function is fine. I hope someone here can tell me what's wrong.
Code:
if(msg == "Cast4"){
typedef int ( __stdcall *Spellcast)(DWORD , DWORD);
Spellcast castmyspell = (Spellcast)0x00B908F0;
castmyspell(6, 0);
}
|
Need some help calling function for height
07/27/2011 - Perfect World - 2 Replies
Hey there, for some reason I keep crashing upon trying to call this function and it's really pissing me off. I was wondering if somebody could give me some advice as to what I'm doing wrong :(
The function is being called inside a function starting at address 0x465730 in PWI
The function I'm looking for is called twice here, namely at 0x4657C7 and 0x465879. The code where it is called looks something like this:
http://img94.imageshack.us/img94/9867/coordfuncti on.png
Now, I'm...
|
Help, calling an ingame function
03/13/2010 - General Coding - 2 Replies
Im trying with my dll to set off the "set stat function". The one that u press when you add a stat point to str, dex or what ever. My goal is to make players able to set there Stats to whatever they use to have from an earlier saved point. So if you play against different sort of mobs or players you reform your stats to be suetable for that sertan task in just 1 second right where you stand. Im thinking this is very useful for many ppl here.
So now i could use help with the actuall call of...
|
Help with calling this function!
03/13/2010 - 12Sky2 - 6 Replies
First off: sorry for my poor english!
Im trying with my dll to set off the "set stat function". The one that u press when you add a stat point to str, dex or what ever. My goal is to make players able to set there Stats to whatever they use to have from an earlier saved point. So if you play against different sort of mobs or players you reform your stats to be suetable for that sertan task in just 1 second right where you stand. Im thinking this is very useful for many ppl here.
So now i...
|
Calling function in a game
03/29/2009 - General Coding - 1 Replies
Hai guise,
I'm a stupid morron but how can I make a hook in c++ that will use Gameplay::GetMoney(); to return the current amount of Gold I have?
http://www.bilderkiste.org/show/original/0bba0c93 80a21de4810c1429cbc287c9/call.jpg
|
All times are GMT +2. The time now is 18:08.
|
|