objectにキャストする

配列をobjectにキャストする – Do You PHP はてな

[php]
(int) $string
[/php]
とかのキャストですが、objectにもできちゃうんですね。

[php]
(object)$arr;
[/php]

知らなかったです。
マニュアルには

配列がオブジェクトに変換される場合、配列のキーがプロパティ名となり、 配列の値がプロパティの値となります。他の値の場合、 scalar という名前のメンバ変数が値を格納します。

こうあります。使う時がくる、、か?

関連する記事:

Powered by

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">