\r
<a href="#top" class="top">top</a>\r
<h2><a name="writing-portable-code"></a>11. Writing Portable Code</h2>\r
- <p>When writing your PHP code please try to use functions that exist since (the minimum requirement) PHP version 4.2.0. If you have to use a function that only exists in later versions of PHP, provide an alternative for older versions. To check if the function is available use either <kbd>version_compare(phpversion(), $min_version)</kbd> or <kbd>function_exists($function_name)</kbd>. For example, to make use of <kbd>file_get_contents()</kbd>, which is only available in PHP 4.3.0 and later, use the following:\r
-<pre class="code">\r
-if (version_compare(phpversion(), '4.3.0') < 0) {\r
- function file_get_contents($filename) {\r
- $fd = @fopen($filename, 'rb');\r
- if ($fd === false) {\r
- $content = false;\r
- } else {\r
- $content = @fread($fd, filesize($filename));\r
- @fclose($fd);\r
- }\r
- return $content;\r
- }\r
-}\r
-</pre></p>\r
+ <p>When writing your PHP code please try to use functions that exist since (the minimum requirement) PHP version 4.3.0. If you have to use a function that only exists in later versions of PHP, provide an alternative for older versions. To check if the function is available use either <kbd>version_compare(phpversion(), $min_version)</kbd> or <kbd>function_exists($function_name)</kbd>.\r
\r
<p>Code has to work on both Windows and UNIX. You should never use <kbd>exec()</kbd> or <kbd>system()</kbd>. In most cases we prefer to write code that works on both systems as is, without the need for if-statements that check for the operating system, since duplicating the functionality twice (once for each operating system) can be a source of bugs. Review the <a href="#php-configuration">PHP Configuration</a> section for details on how best to set-up your development environment.</p>\r
\r