Skip to content

Instantly share code, notes, and snippets.

View guilhermeblanco's full-sized avatar

Guilherme Blanco guilhermeblanco

  • Orlando, FL, USA
  • 23:37 (UTC -04:00)
View GitHub Profile
@nikic
nikic / objects_arrays.md
Last active April 12, 2024 17:05
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

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:

@banaslee
banaslee / XGH - en.txt
Last active May 9, 2024 17:16
eXtreme Go-Horse Process
eXtreme Go Horse (XGH) Process
Source: http://gohorseprocess.wordpress.com
1. I think therefore it's not XGH.
In XGH you don't think, you do the first thing that comes to your mind. There's not a second option as the first one is faster.
2. There are 3 ways of solving a problem: the right way, the wrong way and the XGH way which is exactly like the wrong one but faster.
XGH is faster than any development process you know (see Axiom 14).
@guilhermeblanco
guilhermeblanco / gist:2369944
Created April 12, 2012 18:38 — forked from hay/gist:1351230
Enterprisify your Java Class Names!
<!doctype html>
<html>
<head>
<title></title>
<style>
body {
background: white;
text-align: center;
padding: 20px;
font-family: Georgia, serif;
@ziadoz
ziadoz / awesome-php.md
Last active May 10, 2024 15:06
Awesome PHP — A curated list of amazingly awesome PHP libraries, resources and shiny things.
@beberlei
beberlei / build.sh
Created January 14, 2012 18:21
ZeroMQ Server (REQ-REP) that embeds PHP
cd /path/php-5.3.9
./configure --enable-embedd
ln -s /path/php-5.3.9/libs/libphp5.so /usr/lib/libphp5.so
ldconfig
g++ -o zmqembed zmqembed.c -I/path/php-5.3.9 -I/path/php-5.3.9/main -I/path/php-5.3.9/Zend -I/path/php-5.3.9/TSRM -L/path/php-5.3.9/libs -lphp5 -lzmq