php php中的StdClass

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php php中的StdClass相关的知识,希望对你有一定的参考价值。

<?php

$book = new stdClass;
$book->title = "Harry Potter and the Prisoner of Azkaban";
$book->author = "J. K. Rowling";
$book->publisher = "Arthur A. Levine Books";
$book->amazon_link = "http://www.amazon.com/dp/0439136369/";


$array = array(
"title" => "Harry Potter and the Prisoner of Azkaban",
"author" => "J. K. Rowling",
"publisher" => "Arthur A. Levine Books",
"amazon_link" => "http://www.amazon.com/dp/0439136369/"
);

$books = (object) $array;

/////

function p($i) {
  echo '<pre>';
  print_r($i);
  echo '</pre>';
}


$t0 = microtime(true);
for ($i=0; $i<1000; $i++) {
    $z = array();
    for ($j=0; $j<1000; $j++) {
        $z['aaa'] = 'aaa';
        $z['bbb'] = 'bbb';
        $z['ccc'] = $z['aaa'].$z['bbb'];
    }
}
echo '<p>arrays: '.(microtime(true) - $t0);
p($z);

$t0 = microtime(true);
for ($i=0; $i<1000; $i++) {
    $z = (object) null;
    for ($j=0; $j<1000; $j++) {
        $z->aaa = 'aaa';
        $z->bbb = 'bbb';
        $z->ccc = $z->aaa.$z->bbb;
    }
}
echo '<p>obj: '.(microtime(true) - $t0);
p($z);

echo '<p> phpversion '.phpversion();

以上是关于php php中的StdClass的主要内容,如果未能解决你的问题,请参考以下文章

PHP的stdClass

PHP stdClass类

PHP new StdClass() 创建空对象

在 PHP 中为 stdClass 对象设置命名空间

PHP 数组 stdClass 对象 - 回声值

未定义的属性:stdClass::codeigniter 3 with php 5.3.6