r/PHPhelp • u/notalentgeek_re • May 31 '19
What are the differences between using object (`stdClass`) and associative array?
After reading this: https://www.webmaster-source.com/2009/08/20/php-stdclass-storing-data-object-instead-array/.
I was wondering what are the differences between using object (stdClass) and associative array? Are there any performance benefit of each others? When should I use array and when should create stdClass instead?
7
Upvotes
1
u/AegirLeet May 31 '19
You should almost never use a plain
stdClass. Arrays are easier to work with and offer better performance (although this won't matter much unless you're instantiating hundreds of thousands of arrays/objects).