legacy.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: legacy_8php-source.html 675 2008-12-26 00:27:14Z gwoo $ */
00003 /**
00004  * Backwards compatibility functions.
00005  *
00006  * With this hack you can use clone() in PHP4 code
00007  * use "clone($object)" not "clone $object"! the former works in both PHP4 and PHP5
00008  *
00009  * PHP versions 4 and 5
00010  *
00011  * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
00012  * Copyright 2005-2008, Cake Software Foundation, Inc.
00013  *                              1785 E. Sahara Avenue, Suite 490-204
00014  *                              Las Vegas, Nevada 89104
00015  *
00016  * Licensed under The MIT License
00017  * Redistributions of files must retain the above copyright notice.
00018  *
00019  * @filesource
00020  * @copyright       Copyright 2005-2008, Cake Software Foundation, Inc.
00021  * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00022  * @package         cake
00023  * @subpackage      cake.cake.libs
00024  * @since           CakePHP(tm) v 0.2.9
00025  * @version         $Revision: 675 $
00026  * @modifiedby      $LastChangedBy: gwoo $
00027  * @lastmodified    $Date: 2008-12-25 16:27:14 -0800 (Thu, 25 Dec 2008) $
00028  * @license         http://www.opensource.org/licenses/mit-license.php The MIT License
00029  */
00030     if (version_compare(phpversion(), '5.0') < 0) {
00031         if (!function_exists("clone")) {
00032             eval ('
00033             function clone($object) {
00034             return $object;
00035             }');
00036         }
00037     }
00038 /**
00039  * Replace file_get_contents()
00040  *
00041  * @internal    resource_context is not supported
00042  * @since       PHP 5
00043  * require PHP 4.0.0 (user_error)
00044  *
00045  * @param unknown_type $filename
00046  * @param unknown_type $incpath
00047  * @return unknown
00048  */
00049     if (!function_exists('file_get_contents')) {
00050         function file_get_contents($filename, $incpath = false) {
00051             if (false === $fh = fopen($filename, 'rb', $incpath)) {
00052                 user_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
00053                 return false;
00054             }
00055             clearstatcache();
00056 
00057             if ($fsize = @filesize($filename)) {
00058                 $data = fread($fh, $fsize);
00059             } else {
00060                 $data='';
00061 
00062                 while (!feof($fh)) {
00063                     $data .= fread($fh, 8192);
00064                 }
00065             }
00066             fclose ($fh);
00067             return $data;
00068         }
00069 }
00070 ?>