我需要创建一个将对象传递给方法的PHP方法,因为参数看起来像这样
UIButton *shareButton=(UIButton*)sender;
UIActivityViewController *activityVC=[[UIActivityViewController alloc] initWithActivityItems:
@[@"Programmatically Shared post Just for testing ",
[ [videosList objectAtIndex:shareButton.tag ]videoUrl]]
applicationActivities:nil];
我该如何设计这个方法?
由于
答案 0 :(得分:1)
Cast
他们从array
到object
-
$status = $myClass ->mymethod(
(object)[
"server" => "localhost",
"user" => "user",
"password" => '123'
]
);
方法是 -
public function mymethod($object)
{
echo $object->server; // or whatever processing you need
}
答案 1 :(得分:0)
您可以将数组类型转换为对象:
<?php
Class myClass {
public function __construct(){
}
public function mymethod($obj){
return $obj;
}
}
$status = (new myClass())->mymethod(
(object)array(
"server" => "localhost",
"user" => "user",
"password" => '123'
)
);
var_dump($status);
/* RETURNS:
object(stdClass)#2 (3) {
["server"]=>
string(9) "localhost"
["user"]=>
string(4) "user"
["password"]=>
string(3) "123"
}
*/