|
-
March 29th, 2009, 10:29 PM
#1
Cannot pass a passed in variable to a function? [PHP5]
I've run into a little problem, chances are the solution is simple but I've yet to uncover the work-around.
I'm trying to take a passed in parameter and pass it into a another function, but it comes out as being null, for example:
The following works fine:
Code:
public function get($ID)
{
$myA = new A();
return $myA->foo(1);
}
I can see that in foo() the value passed in is '1' as expected (obviously).
However when I try the following it seems to fail:
Code:
public function get($ID)
{
$myA = new A();
return $myA->foo($ID);
}
The difference is that I am passing in $id from get($ID) into foo($ID) - why doesn't this work?
The parameter in foo($ID) comes out as being NULL (unless I am not seeing this right).
Do I need to do like $temp = $ID and pass foo($temp) instead?
Any help would be much appreciated.
Thanks,
-
March 30th, 2009, 08:59 AM
#2
Re: Cannot pass a passed in variable to a function? [PHP5]
You must have something incorrectly setup in your class. It works fine for me. Here's your code modified a little.
PHP Code:
<?php class A { function foo($param) { echo $param; } }
function get($ID) { $myA = new A(); return $myA->foo($ID); }
get("Testing"); ?>
Once again, it appears as though you are confusing another languages syntax with PHP. In PHP, you do not declare a function as public unless it is a public function within a class.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|