summaryrefslogtreecommitdiff
path: root/inc/compatibility.php
blob: 2738c9bb10ec77921cf1cbf68ea7071d7e9dc531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
 * compatibility functions
 *
 * This file contains a few functions that might be missing from the PHP build
 */

if(!function_exists('ctype_space')) {
    /**
     * Check for whitespace character(s)
     *
     * @see ctype_space
     * @param string $text
     * @return bool
     */
    function ctype_space($text) {
        if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
        if(trim($text) === '') return true;
        return false;
    }
}

if(!function_exists('ctype_digit')) {
    /**
     * Check for numeric character(s)
     *
     * @see ctype_digit
     * @param string $text
     * @return bool
     */
    function ctype_digit($text) {
        if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
        if(preg_match('/^\d+$/', $text)) return true;
        return false;
    }
}

if(!function_exists('gzopen') && function_exists('gzopen64')) {
    /**
     * work around for PHP compiled against certain zlib versions #865
     *
     * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
     *
     * @param string    $filename
     * @param string    $mode
     * @param int $use_include_path
     * @return mixed
     */
    function gzopen($filename, $mode, $use_include_path = 0) {
        return gzopen64($filename, $mode, $use_include_path);
    }
}