如果我们有一个PHP数组并将其转换为对象,是否需要重新分配变量?对此有什么性能上的好处?
$key_value = ('key1'=>'value1' , 'key2'=>'value2');
$key_value = (object)$key_value; //We can reassign as an object
//Is there a way to, without reassigning, just cast the type of the already assigned variable?
//Is this advantageous in terms of performance?
(object)$key_value; //is this the correct syntax, considering it is even possible?
在大多数情况下,这可能无关紧要,但这让我对它背后的理论感到好奇。