PHP StdClass() properties
I'm having some issues with the Std开发者_StackOverflowClass() object in PHP..
I'm using it to send information (a string and boolean) to a function. Outside the function, it works great.
$args = new StdClass();
$args->str = "hej";
$args->ic = TRUE;
fun($arg);
This is then the function called:
function fun($args) {
$str = $args->str;
$ignore_case = $args->ic;
echo $str;
echo $ignore_case;
}
which just writes "stric" instead of the variable contents. Is there a way to use StdClass to transfer this data and read it correctly?
//Martin
function fun($args) {
$str = $args->str;
$ignore_case = $args->ic;
echo $str;
echo $ignore_case;
}
add $
and second echo should be $ignore_case
- I believe
$args = new StdClass();
$args->str = "hej";
$args->ic = TRUE;
fun($arg);
Where is $arg
defined? Your call should be fun($args)
.
You forgot the $
before the variable names in your echo
s.
echo $str;
echo $ignore_case;
Also, fun($arg);
should be fun($args);
精彩评论