PHP

The way to avoid eval() usage when you receive data in PHP code

There is old known situation. We have script or service which gives us PHP arrays packed into strings as PHP code.(In  var_export() format). Or this is historically, something in the system gives us  arrays in PHP code format.

For example your script receives something like:

$test = "array('gmt' => 'Europe/Moscow',
'sudia3' => '',
'sudia1' => '',
'sudia2' => '',
'pos1' => '4-2-3-1',
'color1' => '#f00',
'pos2' => '4-4-1-1',
'color2' => '#000',
);";

PHP. var_dump, pointers and recursion. Why xdebug may be useful

This situation is quite rare, but still occurs. There is a certain variable, and we need look at its structure.

We do the following:

var_dump($fields);

and get into the mess looking on the following message in our log of webserver:

[Thu Feb 23 16:21:07 2012] [error] [client 127.0.0.1] PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 78045652 bytes) in /web/site1/includes/theme.inc on line 1080, referer: http://localhost/site1/

Subscribe to RSS - PHP