Did you think I wouldn’t recognize this compromise

On Thursday, commenter Grumqa asked how PHP deals with the slow accumulation of functions if you call create_function.

It doesn’t.

<?php
for ($i = 0; $i < 100000; $i++)
    create_function("", "return 0;");
?>

This script fairly reliably kills the interpreter with the message “Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40 bytes) …”. You can postpone it by increasing PHP’s memory limit, but if you call create_function an arbitrary number of times, eventually you will murder the interpreter. The only safe way to use create_function is by ensuring you only call it a bounded number of times, and at that point, why not use a normal function and be done with it?

Naturally, the PHP team doesn’t think this is a problem.

One Response to “Did you think I wouldn’t recognize this compromise”

  1. [...] Finite Hate Machine PHP is not my favourite language. « Did you think I wouldn’t recognize this compromise [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped=""> (Syntax highlighting)