@@ -6,22 +6,23 @@ function gettype(mixed_var) {
6
6
// improved by: Brett Zamir (http://brett-zamir.me)
7
7
// input by: KELAN
8
8
// depends on: is_float
9
+ // note: php.js treats objects as associative arrays, so unless config is set, it will return "array" for objects
9
10
// note: 1.0 is simplified to 1 before it can be accessed by the function, this makes
10
11
// note: it different from the PHP implementation. We can't fix this unfortunately.
11
12
// example 1: gettype(1);
12
13
// returns 1: 'integer'
13
14
// example 2: gettype(undefined);
14
15
// returns 2: 'undefined'
15
- // example 3: gettype({0: 'Kevin van Zonneveld'});
16
- // returns 3: 'object'
17
- // example 4: gettype('foo');
18
- // returns 4: 'string'
19
- // example 5: gettype({0: function () {return false;}});
20
- // returns 5: 'object'
21
- // example 6: gettype({0: 'test', length: 1, splice: function () {}});
22
- // example 6: gettype(['test']);
23
- // returns 6: 'object'
16
+ // example 3: gettype('foo');
17
+ // returns 3: 'string'
18
+ // example 4: gettype(['test']);
19
+ // returns 4: 'array'
20
+ // example 5: gettype({0: 'Kevin van Zonneveld'});
21
+ // returns 5: 'array'
22
+ // example 6: gettype({0: function () {return false;}});
24
23
// returns 6: 'array'
24
+ // example 7: gettype({0: 'test', length: 1, splice: function () {}});
25
+ // returns 7: 'array'
25
26
26
27
var s = typeof mixed_var ,
27
28
name ;
@@ -37,7 +38,22 @@ function gettype(mixed_var) {
37
38
if ( mixed_var !== null ) { // From: http://javascript.crockford.com/remedial.html
38
39
if ( typeof mixed_var . length === 'number' && ! ( mixed_var . propertyIsEnumerable ( 'length' ) ) && typeof mixed_var
39
40
. splice === 'function' ) {
40
- s = 'array' ;
41
+
42
+ // BEGIN REDUNDANT
43
+ this . php_js = this . php_js || { } ;
44
+ this . php_js . ini = this . php_js . ini || { } ;
45
+ // END REDUNDANT
46
+
47
+ // Call ini_set('phpjs.objectsAsArrays', 0) to disallow objects as arrays
48
+ ini = this . php_js . ini [ 'phpjs.objectsAsArrays' ] ;
49
+ if ( ! ini || ( // if it's not set to 0 and it's not 'off', check for objects as arrays
50
+ ( parseInt ( ini . local_value , 10 ) !== 0 && ( ! ini . local_value . toLowerCase || ini . local_value . toLowerCase ( ) !==
51
+ 'off' ) ) ) ) {
52
+ s = 'object' ;
53
+ }
54
+ else {
55
+ s = 'array' ;
56
+ }
41
57
} else if ( mixed_var . constructor && getFuncName ( mixed_var . constructor ) ) {
42
58
name = getFuncName ( mixed_var . constructor ) ;
43
59
if ( name === 'Date' ) {
0 commit comments