如何从PHP中的函数返回哈希对象?

Mat*_*ris -4 php curl function object

我想做一些我确信很简单的事情,但我不能从文档中收集如何做到这一点.

我想做的就是:

function something() {
 // Do some stuff with cURL
 set $object->name;
 set $object->corporation;
 // some if statement
 set $object->other; //if cURL finds "other" exists

 return $object;
}
Run Code Online (Sandbox Code Playgroud)

并且能够做到这一点:

$result = something();
$name = $result->name;
etc.
Run Code Online (Sandbox Code Playgroud)

有谁知道最好的方法吗?我使用程序风格,对物体知之甚少,因此我正在努力学习.

小智 6

function foo(){
    $result = new stdClass();
    $result->name = "Joe";
    $result->other = "bar";
    return $result;
}
$object = foo();
echo $object->name; // Should display "Joe"
Run Code Online (Sandbox Code Playgroud)