from.. 2009-05-31 05:49 采纳率: 100%
浏览 360
已采纳

Php 中什么是 stdClass?

Please define what stdClass is.

转载于:https://stackoverflow.com/questions/931407/what-is-stdclass-in-php

  • 写回答

16条回答 默认 最新

  • MAO-EYE 2009-05-31 05:55
    关注

    stdClass is PHP's generic empty class, kind of like Object in Java or object in Python (Edit: but not actually used as universal base class; thanks @Ciaran for pointing this out).

    It is useful for anonymous objects, dynamic properties, etc.

    An easy way to consider the StdClass is as an alternative to associative array. See this example below that shows how json_decode() allows to get an StdClass instance or an associative array. Also but not shown in this example, SoapClient::__soapCall returns an StdClass instance.

    <?php
    //Example with StdClass
    $json = '{ "foo": "bar", "number": 42 }';
    $stdInstance = json_decode($json);
    echo $stdInstance->foo . PHP_EOL; //"bar"
    echo $stdInstance->number . PHP_EOL; //42
    //Example with associative array
    $array = json_decode($json, true);
    echo $array['foo'] . PHP_EOL; //"bar"
    echo $array['number'] . PHP_EOL; //42
    

    See Dynamic Properties in PHP and StdClass for more examples.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(15条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀