Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

22
  • 3
    Also consider the ArrayAccess interface, perhaps in combination with this solution. php.net/manual/en/class.arrayaccess.php Commented Aug 8, 2014 at 13:53
  • 4
    It you have integer keys the'll be converted in to string and this can cause big issue. E.g. [1 => "one"] becomes ["1" => "one"] Commented Aug 11, 2015 at 12:16
  • 3
    @Howie Typecasting with (array) and (object) works reliably and the same across all versions since PHP 4.3. See 3v4l.org/X6lhm. If you get a syntax error, you did something wrong. Commented Nov 30, 2015 at 10:26
  • 2
    @Howie see the Changelog section for empty. You cannot use an expression with empty prior to 5.5. This is completely unrelated to typecasting ;) Commented Dec 1, 2015 at 10:48
  • 2
    Attention!!! Integer properties become unaccessible. Though they can be seen via print_r etc. Commented Aug 7, 2018 at 11:05