/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * api: php * title: upgrade.php * description: backwards compatibility for older PHP interpreters * version: 14 * license: Public Domain * url: http://freshmeat.net/p/upgradephp * type: functions * category: library * priority: auto * sort: -200 * provides: upgrade-php * * * You get PHP version independence by including() this script. It provides * downwards compatibility to older PHP installations by emulating missing * functions or constants using IDENTICAL NAMES. So this doesn't slow down * script execution on setups where the native functions already exist. It * is meant as quick drop-in solution, and to free you from rewriting or * cumbersome workarounds - instead of using the real & more powerful funcs. * * It cannot mirror PHP5s extended OO-semantics and functionality into PHP4 * however. A few features are added here that weren't part of PHP yet. And * some other function collections are separated out into the ext/ directory. * * And further this is PUBLIC DOMAIN (no copyright, no license, no warranty) * so threrefore compatible to ALL open source licenses. You could rip this * paragraph out to republish this instead only under more restrictive terms * or your favorite license (GNU LGPL/GPL, BSDL, MPL/CDDL, Artist, PHPL, ...) * * Get update notes via "http://freshmeat.net/projects/upgradephp" or * google for it. Any contribution is appreciated. <milky*users·sf·net> * */ /** * ------------------------------ CVS --- * @group CVS * @since CVS * * planned, but as of yet unimplemented functions * - some of these might appear in 6.0 or ParrotPHP * * @emulated * sys_get_temp_dir * */ /** * returns path of the system directory for temporary files * */ # check possible alternatives or ($temp = $_SERVER["TEMP"]) or ($temp = $_SERVER["TMP"]) or ($temp = "/tmp"); # fin return($temp); } } /** * ------------------------------ 5.2 --- * @group 5_2 * @since 5.2 * * Additions of PHP 5.2.0 * - some listed here, might have appeared earlier or in release candidates * * @emulated * json_encode * json_decode * error_get_last * preg_last_error * lchown * lchgrp * E_RECOVERABLE_ERROR * M_SQRTPI * M_LNPI * M_EULER * M_SQRT3 * * @missing * sys_getloadavg * inet_ntop * inet_pton * array_fill_keys * array_intersect_key * array_intersect_ukey * array_diff_key * array_diff_ukey * array_product * pdo_drivers * ftp_ssl_connect * XmlReader * XmlWriter * PDO* * * @unimplementable * stream_* * */ /** * @since unknown */ /** * Converts PHP variable or array into "JSON" (a JavaScript value expression * or "object notation"). * * @compat * output seems identical to PECL versions * @bugs * doesn't take care with unicode too much * */ #-- prepare JSON string $json = ""; #-- add array entries #-- check if array is associative $obj = 1; break; } } #-- concat invidual entries $json .= ($json ? "," : "") // comma separators . ($obj ? ("\"$i\":") : "") // assoc prefix } #-- enclose into braces or brackets $json = $obj ? "{".$json."}" : "[".$json."]"; } #-- strings need some care } $var = str_replace(array("\"", "\\", "/", "\b", "\f", "\n", "\r", "\t"), array("\\\"", "\\\\", "\\/", "\\b", "\\f", "\\n", "\\r", "\\t"), $var); $json = '"' . $var . '"'; } #-- basic types $json = $var ? "true" : "false"; } elseif ($var === NULL) { $json = "null"; } $json = "$var"; } #-- something went wrong else { } #-- done return($json); } } /** * Parses JSON (JavaScript value expression) into PHP variable * (array or object). * * @compat * behaves similiar to PECL version * but is less quiet on errors * might ignore some misformed representations * @bugs * doesn't decode unicode \uXXXX string escapes * */ #-- result var $val = NULL; static $str_eq = array("n"=>"\012", "r"=>"\015", "\\"=>"\\", '"'=>'"', "f"=>"\f", "b"=>"\b", "t"=>"\t", "/"=>"/"); #-- flat char-wise parsing $c = $json[$n]; #-= in-string if ($state==='"') { if ($c == '\\') { $c = $json[++$n]; $val .= $str_eq[$c]; } elseif ($c == "u") { $val .= "\\u"; } else { $val .= "\\" . $c; } } elseif ($c == '"') { $state = 0; } else { $val .= $c; } } #-> end of sub-call (array/object) } #-= in-array elseif ($state===']') { $val[] = $v; } #-= in-object elseif ($state==='}') { $val[$i] = $v; } #-- looking for next item (0) else { #-> whitesapce // skip } #-> string begin elseif ($c == '"') { $state = '"'; } #-> object elseif ($c == "{") { if ($val && $n && !$assoc) { $obj = new stdClass(); foreach ($val as $i=>$v) { $obj->{$i} = $v; } $val = $obj; } } #-> array elseif ($c == "[") { } #-> comment elseif (($c == "/") && ($json[$n+1]=="*")) { // just find end, skip over } #-> numbers $val = $uu[1]; } } #-> boolean or null $val = $lang_eq[$uu[1]]; } #-- parsing error else { // PHPs native json_decode() breaks here usually and QUIETLY } }//state #-- next char if ($n === NULL) { return NULL; } $n++; }//for #-- final result return ($val); } } /** * @stub * @cannot-reimplement * */ return PREG_NO_ERROR; } } /** * @stub * * Returns associative array with last error message. * */ "type" => 0, "message" => $GLOBALS[php_errormsg], "file" => "unknonw", "line" => 0, ); } } /** * @flag quirky, exec * * Change owner/group of a symlink filename. * */ function lchown($fn, $user) { if (PHP_OS != "Linux") { return false; } return($state); } } function lchgrp($fn, $group) { return lchown($fn, ":$group"); } } /** * ------------------------------ 5.1 --- * @group 5_1 * @since 5.1 * * Additions in PHP 5.1 * - most functions here appeared in -rc1 already * - and were backported to 4.4 series? * * @emulated * property_exists * time_sleep_until * fputcsv * strptime * ENT_COMPAT * ENT_QUOTES * ENT_NOQUOTES * htmlspecialchars_decode * PHP_INT_SIZE * PHP_INT_MAX * M_SQRTPI * M_LNPI * M_EULER * M_SQRT3 * * @missing * strptime * * @unimplementable * ... * */ /** * Constants for future 64-bit integer support. * */ /** * @flag bugfix * @see #33895 * * Missing constants in 5.1, originally appeared in 4.0. */ #-- removes entities < > & and " eventually from HTML string $d = $quotes & ENT_COMPAT; $s = $quotes & ENT_QUOTES; $string ); } } /** * @flag quirky, needs5 * * Checks for existence of object property, should return TRUE even for NULL values. * * @compat * uses (array) conversion to test, but that might not always work * @bugs * probably can't handle static classes well */ # doesn't return true for NULL values, can't handle public/private function property_exists($obj, $prop) { $obj = new $obj(); } } } } #-- halt execution, until given timestamp // I wonder who always comes up with such useless function ideas function time_sleep_until($t) { if ($delay < 0) { return false; } else { return true; } } } /** * @untested * * Writes an array as CSV text line into opened filehandle. * */ $line = ""; $line .= ($line ? $delim : "") . $encl . $encl; } } } /** * @stub * @untested * @flag basic * * @compat * only implements a few basic regular expression lookups * no idea how to handle all of it */ function strptime($str, $format) { "%D" => "%m/%d/%y", "%T" => "%H:%M:%S", ); "%S"=>"tm_sec", "%M"=>"tm_min", "%H"=>"tm_hour", "%d"=>"tm_mday", "%m"=>"tm_mon", "%Y"=>"tm_year", "%y"=>"tm_year", "%W"=>"tm_wday", "%D"=>"tm_yday", "%u"=>"unparsed", ); "Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12, "Sun" => 0, "Mon" => 1, "Tue" => 2, "Wed" => 3, "Thu" => 4, "Fri" => 5, "Sat" => 6, ); #-- transform $format into extraction regex #-- record the positions of all STRFCMD-placeholders $positions = $positions[1]; #-- get individual values #-- get values foreach ($positions as $pos=>$strfc) { $v = $extracted[$pos + 1]; #-- add if ($n = $map_r[$strfc]) { $vals[$n] = ($v > 0) ? (int)$v : $v; } else { $vals["unparsed"] .= $v . " "; } } #-- fixup some entries if ($vals["tm_year"] >= 1900) { $tm_year -= 1900; } elseif ($vals["tm_year"] > 0) { $vals["tm_year"] += 100; } if ($vals["tm_mon"]) { $vals["tm_mon"] -= 1; } else { } #-- calculate wday // ... (mktime) } } } /** * --------------------------- FUTURE --- * @group FUTURE * @since unknown * * Following functions aren't implemented in current PHP versions allthough * they are logical and required counterparts to existing features or exist * in the according external library. * * @emulated * gzdecode * ob_get_headers * xmlentities * * @missing * ... * * @unimplementable * ... * */ #-- inflates a string enriched with gzip headers # (this is the logical counterpart to gzencode(), but don't tell anyone!) function gzdecode($data, $maxlen=NULL) { #-- decode header if ($len < 20) { return; } $FTEXT = 1<<0; $FHCRC = 1<<1; $FEXTRA = 1<<2; $FNAME = 1<<3; $FCOMMENT = 1<<4; #-- check gzip stream identifier if ($ID != 0x1f8b) { return; } #-- check for deflate algorithm if ($CM != 8) { return; } #-- start of data, skip bonus fields $s = 10; if ($FLG & $FEXTRA) { $s += $XFL; } if ($FLG & $FNAME) { } if ($FLG & $FCOMMENT) { } if ($FLG & $FHCRC) { $s += 2; // cannot check } #-- get data, uncompress if ($maxlen) { return($data); // no checks(?!) } else { } #-- check+fin if ($CRC32 != $chk) { } } else { return($data); } } } #-- get all already made headers(), # CANNOT be emulated, because output buffering functions # already swallow up any sent http header function ob_get_headers() { } } #-- encodes required named XML entities, like htmlentities(), # but does not re-encode numeric &#xxxx; character references # - could screw up scripts which then implement this themselves # - doesn't fix bogus or invalid numeric entities function xmlentities($str) { "&#"=>"&#", "&"=>"&", "'"=>"'", "<"=>"<", ">"=>">", "\""=>""", )); } } /** * ------------------------------ 5.0 --- * @group 5_0 * @since 5.0 * * PHP 5.0 introduces the Zend Engine 2 with new object-orientation features * which cannot be reimplemented/defined for PHP4. The additional procedures * and functions however can. * * @emulated * stripos * strripos * str_ireplace * get_headers * headers_list * fprintf * vfprintf * str_split * http_build_query * convert_uuencode * convert_uudecode * scandir * idate * time_nanosleep * strpbrk * get_declared_interfaces * array_combine * array_walk_recursive * substr_compare * spl_classes * class_parents * session_commit * dns_check_record * dns_get_mx * setrawcookie * file_put_contents * COUNT_NORMAL * COUNT_RECURSIVE * count_recursive * FILE_USE_INCLUDE_PATH * FILE_IGNORE_NEW_LINES * FILE_SKIP_EMPTY_LINES * FILE_APPEND * FILE_NO_DEFAULT_CONTEXT * E_STRICT * * @missing * proc_nice * dns_get_record * date_sunrise - undoc. * date_sunset - undoc. * PHP_CONFIG_FILE_SCAN_DIR * * @unimplementable * set_exception_handler * restore_exception_handler * debug_print_backtrace * class_implements * proc_terminate * proc_get_status * */ #-- constant: end of line #-- case-insensitive string search function, # - finds position of first occourence of a string c-i # - parameters identical to strpos() #-- simply lowercase args #-- search return($pos); } } #-- case-insensitive string search function # - but this one starts from the end of string (right to left) # - offset can be negative or positive #-- lowercase incoming strings #-- [-]$offset tells to ignore a few string bytes, # we simply cut a bit from the right } #-- let PHP do it #-- [+]$offset => ignore left haystack bytes $pos = false; } #-- result return($pos); } } #-- case-insensitive version of str_replace #-- call ourselves recursively, if parameters are arrays/lists } } #-- sluice replacement strings through the Perl-regex module # (faster than doing it by hand) else { } #-- result return($subject); } } #-- performs a http HEAD request #-- extract URL parts ($host, $port, $path, ...) $port = 80; } #-- try to open TCP connection if (!$f) { return; } #-- send request header . "Host: $host\015\012" . "Connection: close\015\012" . "Accept: */*, xml/*\015\012" . "\015\012"); #-- read incoming lines #-- read header names to make result an hash (names in array index) if ($parse) { #-- merge headers $ls[$name] .= ", $value"; } else { $ls[$name] = $value; } } #-- HTTP response status header as result[0] else { $ls[] = $line; } } #-- unparsed header list (numeric indices) else { $ls[] = $line; } } #-- close TCP connection and give result return($ls); } } #-- list of already/potentially sent HTTP responsee headers(), # CANNOT be implemented (except for Apache module maybe) } } #-- write formatted string to stream/file, # arbitrary numer of arguments } } #-- write formatted string to stream, args array } } #-- splits a string in evenly sized chunks # and returns this as array #-- return back as one chunk completely, if size chosen too low if ($chunk < 1) { $r[] = $str; } #-- add substrings to result array until subject strings end reached else { for ($n=0; $n<$len; $n+=$chunk) { } } return($r); } } #-- constructs a QUERY_STRING (application/x-www-form-urlencoded format, non-raw) # from a nested array/hash with name=>value pairs # - only first two args are part of the original API - rest used for recursion #-- empty starting string $s = ""; #-- traverse hash/array/list entries foreach ($data as $index=>$value) { #-- add sub_prefix for subarrays (happens for recursed innovocation) if ($subarray_pfix) { if ($level) { $index = "[" . $index . "]"; } $index = $subarray_pfix . $index; } #-- add user-specified prefix for integer-indices $index = $int_prefix . $index; } #-- recurse for sub-arrays } else { // or just literal URL parameter } } #-- remove redundant "&" from first round (-not checked above to simplifiy loop) if (!$subarray_pfix) { } #-- return result / to previous array level and iteration return($s); } } #-- transform into 3to4 uuencode # - this is the bare encoding, not the uu file format #-- init vars $out = ""; $line = ""; # $data .= "\252\252\252"; // PHP and uuencode(1) use some special garbage??, looks like "\000"* and "`\n`" simply appended #-- canvass source string for ($n=0; $n<$len; ) { #-- make 24-bit integer from first three bytes #-- disperse that into 4 ascii characters #-- cut lines, inject count prefix before each if (($n % 45) == 0) { $line = ""; } } #-- throw last line, +length prefix if ($trail = ($len % 45)) { } // uuencode(5) doesn't tell so, but spaces are replaced with the ` char in most implementations return($out); } } #-- decodes uuencoded() data again #-- prepare $out = ""; #-- go through lines break; // end reached } #-- current line length prefix if (($num <= 0) || ($num > 62)) { // 62 is the maximum line length break; // according to uuencode(5), so we stop here too } #-- prepare to decode 4-char chunks $add = ""; #-- merge 24 bit integer from the 4 ascii characters (6 bit each) #-- reconstruct the 3 original data chars } #-- cut any trailing garbage (last two decoded chars may be wrong) $line = ""; } return($out); } } #-- return array of filenames in a given directory # (only works for local files) #-- check for file:// protocol, others aren't handled } } #-- directory reading handle $ls[] = $fn; // add to array } #-- sort filenames if ($desc) { } else { } return $ls; } #-- failure return false; } } #-- like date(), but returns an integer for given one-letter format parameter #-- reject non-simple type parameters return false; } #-- get current time, if not given } #-- get and turn into integer return (int)$str; } } #-- combined sleep() and usleep() function time_nanosleep($sec, $nano) { } } #-- search first occourence of any of the given chars, returns rest of haystack # (char_list must be a string for compatibility with the real PHP func) #-- prepare #-- check with every symbol from $char_list for ($n = 0; $n < $len; $n++) { #-- get left-most occourence if (($l !== false) && ($l < $min)) { $min = $l; } } #-- result if ($min) { } else { return(false); } } } #-- logo image activation URL query strings (gaga feature) } #-- no need to implement this # (there aren't interfaces in PHP4 anyhow) function get_declared_interfaces() { trigger_error("get_declared_interfaces(): Current script won't run reliably with PHP4.", E_USER_WARNING); } } #-- creates an array from lists of $keys and $values # (both should have same number of entries) #-- convert input arrays into lists #-- one from each foreach ($values as $i=>$val) { if ($key = $keys[$i]) { $r[$key] = $val; } else { $r[] = $val; // useless, PHP would have long aborted here } } return($r); } } #-- apply userfunction to each array element (descending recursively) # use it like: array_walk_recursive($_POST, "stripslashes"); # - $callback can be static function name or object/method, class/method #-- each entry foreach ($input as $key=>$value) { #-- recurse for sub-arrays } #-- $callback handles scalars else { } } // no return value } } #-- complicated wrapper around substr() and and strncmp() #-- check params if ($len <= 0) { // not well documented if (!$len) { return(0); } } #-- length exception return(false); } #-- cut if ($offset) { } #-- case-insensitivity if ($ci) { } #-- do } } #-- stub, returns empty list as usual; # you must load "ext/spl.php" beforehand to get this } } #-- gets you list of class names the given objects class was derived from, slow #-- first get full list #-- filter out foreach ($all as $potential_parent) { $r[$potential_parent] = $potential_parent; } } return($r); } } #-- an alias // simple } } #-- aliases function dns_check_record($host, $type=NULL) { // synonym to } } function dns_get_mx($host, $mx) { // simple alias - except the optional, but referenced third parameter if ($args[2]) { $w = & $args[2]; } else { $w = false; } } } #-- setrawcookie(), # can this be emulated 100% exactly? // we output everything directly as HTTP header(), PHP doesn't seem // to manage an internal cookie list anyhow ' and some other control chars; thrown away", E_USER_WARNING); } else { $h = "Set-Cookie: $name=$value" . ($path ? "; path=$path": "") . ($domain ? "; domain=$domain" : "") . ($secure ? "; secure" : ""); } } } #-- write-at-once file access (counterpart to file_get_contents) #-- prepare $mode = ($flags & FILE_APPEND ? "a" : "w" ) ."b"; $incl = $flags & FILE_USE_INCLUDE_PATH; #-- open for writing if ($f) { #-- only report success, if completely saved return($length == $written); } } } #-- file-related constants #-- more new constants for 5.0 # PHP_CONFIG_FILE_SCAN_DIR #-- array count_recursive() #-- we introduce a new function, because we cannot emulate the # newly introduced second parameter to count() function count_recursive($array, $mode=1) { if (!$mode) { } else { foreach ($array as $sub) { $c += count_recursive($sub); } } return($c); } } } /** * ------------------------------ 4.4 --- * @group 4_4 * @since 4.4 * * PHP 4.4 is a bugfix and backporting version created after PHP 5. It went * mostly unchanged, but changes a few language semantics (e.g. references). * * @emulated * PHP_INT_SIZE * PHP_INT_MAX * SORT_LOCALE_STRING * */ /** * ------------------------------ 4.3 --- * @group 4_3 * @since 4.3 * * Additions in 4.3 version of PHP interpreter. * * @emulated * file_get_contents * array_key_exists * array_intersect_assoc * array_diff_assoc * html_entity_decode * str_word_count * str_shuffle * get_include_path * set_include_path * restore_include_path * fnmatch * FNM_PATHNAME * FNM_NOESCAPE * FNM_PERIOD * FNM_LEADING_DIR * FNM_CASEFOLD * FNM_EXTMATCH * glob * GLOB_MARK * GLOB_NOSORT * GLOB_NOCHECK * GLOB_NOESCAPE * GLOB_BRACE * GLOB_ONLYDIR * GLOB_NOCASE * GLOB_DOTS * __FUNCTION__ * PATH_SEPARATOR * PHP_SHLIB_SUFFIX * PHP_SAPI * PHP_PREFIX * * @missing * sha1_file * sha1 - too much code, and has been reimplemented elsewhere * * @unimplementable * money_format * */ #-- simplified file read-at-once function #-- open file, let fopen() report error if (!$f) { return; } #-- read max 2MB return($content); } } #-- shell-like filename matching (* and ? globbing characters) #-- associated constants #-- implementation #-- 'hidden' files if ($flags & FNM_PERIOD) { if (($str[0] == ".") && ($pattern[0] != ".")) { return(false); // abort early } } #-- case-insensitivity $rxci = ""; if ($flags & FNM_CASEFOLD) { $rxci = "i"; } #-- handline of pathname separators (/) $wild = "."; if ($flags & FNM_PATHNAME) { $wild = "[^/".DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR."]"; } #-- check for cached regular expressions $rx = $cmp["$pattern+$flags"]; } #-- convert filename globs into regex else { "\\*"=>"$wild*?", "\\?"=>"$wild", "\\["=>"[", "\\]"=>"]", )); $rx = "{^" . $rx . "$}" . $rxci; #-- cache } $cmp["$pattern+$flags"] = $rx; } #-- compare } } #-- file search and name matching (with shell patterns) #-- introduced constants // unlikely to work under Win(?), without replacing the explode() with // a preg_split() incorporating the native DIRECTORY_SEPARATOR as well #-- implementation $rxci = ($flags & GLOB_NOCASE) ? "i" : ""; #echo "\n=> glob($pattern)...\n"; #-- transform glob pattern into regular expression # (similar to fnmatch() but still different enough to require a second func) if ($pattern) { #-- look at each directory/fn spec part separately if ($flags ^ GLOB_NOESCAPE) { // uh, oh, ouuch - the above is unclean enough... } if ($flags ^ GLOB_BRACE) { } #echo "parts == ".implode(" // ", $parts) . "\n"; $dn = ""; foreach ($parts as $i=>$p) { #-- basedir included (yet no pattern matching necessary) $dn .= $parts2[$i] . ($i!=$lasti ? "/" : ""); #echo "skip:$i, cause no pattern matching char found -> only a basedir spec\n"; continue; } #-- start reading dir + match filenames against current pattern $with_dot = ($p[1]==".") || ($flags & GLOB_DOTS); #echo "part:$i:$p\n"; #echo "reading dir \"$dn\"\n"; #-- skip over 'hidden' files if (($fn[0] == ".") && !$with_dot) { continue; } #-- add filename only if last glob/pattern part if ($i==$lasti) { if ($flags & GLOB_ONLYDIR) { continue; } if ($flags & GLOB_MARK) { $fn .= "/"; } } #echo "adding '$fn' for dn=$dn to list\n"; $ls[] = "$dn$fn"; } #-- initiate a subsearch, merge result list in // add reamaining search patterns to current basedir } } } #-- prevent scanning a 2nd part/dir in same glob() instance: break; } #-- given dirname doesn't exist else { return($ls); } }// foreach $parts } #-- return result list if (!$ls && ($flags & GLOB_NOCHECK)) { $ls[] = $pattern; } if ($flags ^ GLOB_NOSORT) { } #print_r($ls); #echo "<=\n"; return($ls); } } //@FIX: fully comment, remove debugging code (- as soon as it works ;) #-- redundant alias for isset() } } #-- who could need that? #-- parameters, prepare #-- walk through each array pair # (take first as checklist) foreach ($in[0] as $i => $v) { for ($c = 1; $c < $cmax; $c++) { #-- remove entry, as soon as it isn't present # in one of the other arrays continue 2; } } #-- it was found in all other arrays $whatsleftover[$i] = $v; } return $whatsleftover; } } #-- the opposite of the above #-- params #-- compare each array with primary/first foreach ($in[0] as $i=>$v) { #-- skip as soon as it matches with entry in another array continue 2; } } #-- else $diff[$i] = $v; } return $diff; } } #-- opposite of htmlentities //@FIX: we fall short on anything other than Latin-1 } } #-- extracts single words from a string #-- let someone else do the work #-- return full word list if ($result == 1) { return($uu[1]); } #-- array() of $pos=>$word entries elseif ($result >= 2) { $l = 0; foreach ($uu[1] as $word) { $r[$l] = $word; } return($r); } #-- only count else { } } } #-- creates a permutation of the given strings characters # (let's hope the random number generator was alread initialized) $r = ""; #-- cut string down with every iteration if ($n) { } #-- cut out elected char, add to result string $r .= $str{$n}; } return($r); } } #-- simple shorthands } } } } #-- constants for 4.3 #-- not identical to what PHP reports (it seems to `which` for itself) #------------------------------------------------------------------ 4.2 --- # almost complete!? #-- shy away from this one - it was broken in all real PHP4.2 versions, and # this function emulation script won't change that static $from = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static $to = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"; } } #-- well, if you need it #-- introduced constants #-- implementation #-- loop through foreach ($array as $i=>$v) { #-- do anything for strings only $array[$i] = $v; } // non-recursive } return($array); } } #-- create fixed-length array made up of $value data #-- params $i = $start_index; $end = $num + $start_index; #-- append for (; $i < $end; $i++) { $r[$i] = $value; } return($r); } } #-- split an array into evenly sized parts #-- array for chunked output $n = -1; // chunk index #-- enum input array blocks foreach ($input as $i=>$v) { #-- new chunk $n++; } #-- add input value into current [$n] chunk if ($preserve_keys) { $r[$n][$i] = $v; } else { $r[$n][] = $v; } } return($r); } } #-- convenience wrapper #-- read file, apply hash function $data = NULL; #-- transform? and return if ($raw_output) { } return $r; } } #-- object type checking #-- lowercase everything for comparison #-- two possible checks } } #-- floating point modulo $r = $x / $y; $r -= (int)$r; $r *= $y; return($r); } } #-- makes float variable from string return (float)$str; } } #-- floats #-- constants as-is #-- simple checks $s = (string)$f; return( ($s=="INF") || ($s=="-INF") ); } $s = (string)$f; return( $s=="NAN" ); } $s = (string)$f; } } #-- throws value-instantiation PHP-code for given variable # (a bit different from the standard, was intentional for its orig use) #-- output as in-class variable definitions } $output .= "}"; } #-- array constructor foreach ($var as $id=>$next) { if ($output) $output .= ",\n"; else $output = "array(\n"; $output .= $indent . ' ' } $output .= "\n{$indent})"; #if ($indent == "") $output .= ";"; } #-- literals $output = "$var"; } $output = $var ? "true" : "false"; } else { } #-- done if ($return) { return($output); } else { print($output); } } } #-- strcmp() variant that respects locale setting, # existed since PHP 4.0.5, but under Win32 first since 4.3.2 } } #------------------------------------------------------------------ 4.1 --- # nl_langinfo - unimpl? # getmygid # version_compare # # See also "ext/math41.php" for some more (rarely used mathematical funcs). #-- aliases (an earlier fallen attempt to unify PHP function names) return disk_free_sapce(); } function disktotalspace() { return disk_total_sapce(); } } #-- variable count of arguments (in array list) printf variant } } #-- same as above, but doesn't output directly and returns formatted string } } #-- can be used to simulate a register_globals=on environment #-- associate abbreviations to global var names "G" => "_GET", "P" => "_POST", "C" => "_COOKIE", "S" => "_SERVER", // non-standard "E" => "_ENV", // non-standard ); #-- alias long names (PHP < 4.0.6) $_GET = & $HTTP_GET_VARS; $_POST = & $HTTP_POST_VARS; $_COOKIE = & $HTTP_COOKIE_VARS; } #-- copy foreach ($$FROM as $key=>$val) { $GLOBALS[$pfix . $key] = $val; } } } } // done } } // a few mathematical functions follow // (wether we should really emulate them is a different question) #-- me has no idea what this function means } } #-- more accurate logarithm func, but we cannot simulate it # (too much work, too slow in PHP) } #-- same story for: } } #-- as per PHP manual } } } } #-- these look a bit more complicated } } } } #-- HMAC from RFC2104, but see also PHP_Compat and Crypt_HMAC #-- constants #-- implementation #-- hash function } if (!$key) { } #-- params #-- pad key $key = $func($key); } #-- prepare inner and outer padding stream #-- call hash func // php can XOR strings for us return($dgst); } #-- return which hash functions are implemented return(MHASH_SHA1); } #-- map numeric identifier to hash function name MHASH_CRC32 => "crc32", // would need dechex()ing in main func? MHASH_MD5 => "md5", MHASH_SHA1 => "sha1", ); } #-- static value return(64); } } #-- other stuff /* removed funcs?? [18] => leak */ #-- pre-4.1 -- end // no need to implement anything below that, because such old versions // will be incompatbile anyhow (- none of the newer superglobals known), // but see also "ext/old" ?>