GET /trucks HTTP/1.1
Host: api.example.com
Authorization: Basic username:password
Accept: application/vnd.hal+json
<?php | |
class DemoSubject implements SplSubject{ | |
private $observer, $value; | |
public function __construct(){ | |
$this->observers = array(); | |
} | |
This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)
The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array
it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array
part of it away. So how does that work?
The key here is that objects usually have a predefined set of keys, whereas arrays don't:
<?php | |
/** | |
* @package Joomla.Plugin | |
* @subpackage System.Overrides | |
* | |
* @copyright Copyright (C) 2012 Don Gilbert. All rights reserved. | |
* @license GNU General Public License version 2 or later; see LICENSE | |
*/ | |
define('OVERRIDES', dirname(__FILE__).'/overrides'); |