1

I'm having some issues with the StdClass() 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

3 Answers 3

2
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

Sign up to request clarification or add additional context in comments.

2 Comments

Oh dear god, my bad... didn't help though, not it just acts like the variables are empty and prints nothing.
@Martinnj: fun($arg); should be fun($args);
1
$args = new StdClass();
$args->str = "hej";
$args->ic = TRUE;
fun($arg);

Where is $arg defined? Your call should be fun($args).

1 Comment

THANS! I misspelled word and everything dies... Thanks a lot!
1

You forgot the $ before the variable names in your echos.

echo $str;
echo $ignore_case;

Also, fun($arg); should be fun($args);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.