Php

From ThorstensHome
Revision as of 17:38, 12 December 2015 by ThorstenStaerk (Talk | contribs)

Jump to: navigation, search

Contents

Debugging

It happens often that I see an empty page where I would expect something. One example is when I migrate a server and have a php script running on a new server. It may turn out that this new server does not have a specific PHP module and that is why it does not work. Similarly, if I forget a ";" at the end of a command, the whole php file will just show nothing in the browser.

output

Here is a php trick that outputs debugging output when you want.

$handler=fopen("/tmp/debug","a");
fwrite ($handler, "hello world");
fclose ($handler);

example for variables:

$handler=fopen("/tmp/debug","a");
fwrite ($handler, var_export($variable,true));
fclose ($handler);

variables' content

var_dump

To output an array use

echo serialize($array)

magic words

Parameters

$argv[1]