理解标准类int PHP(并非工作示例)

So in this answer to the question: Hidden Features of PHP?

Talks about using standard classes in PHP. Which in his own example looks sweet but I cant get it to work, se here.

The code is:

<?php

$person = new stdClass();
$person->name = 'bob';
$person->age = 5;

$string = "$person->name is $person->age years old.";

?>

I realize I may be completely misinterpreting the answer but anyway, this is what I understood :)

The this I don't understand is (the most important probably) stdClass(); I read: What is stdClass in PHP? but I think I'm even more confused now. (I did't find the accepted answer very useful to be honest)

Thanks in advance!!


EDIT:

Damn!! I'm sorry guys!! I was not code related!! when I copy the code to ideone.com I just copies some other values with it and prevents it from working (or at least this is my best guess) works just fine in codepad.org, I'm switching!!

Works for me.

Is your PHP > 5.1?

Try this

var_dump(version_compare(PHP_VERSION, 5.1, '>'));

Update

Your example works for me. Did you forget to output your string? :P

In order to interpolate object members within strings in older versions of PHP, you should surround them with curly braces:

$string = "{$person->name} is {$person->age} years old.";

When you use mysql_fetch_object() it returns an instance of stdClass. The columns are the properties of this class. It's like an anonymous class. It's because PHP doesn't have a class for every possible table in the world. So this is very handy.