Skip to content

Commit 65fde86

Browse files
committed
Fix #336: bug in is_numeric functions
1 parent 92484e2 commit 65fde86

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

jphp-runtime/src/php/runtime/ext/core/LangFunctions.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
import php.runtime.lang.ForeachIterator;
2626
import php.runtime.lang.IObject;
2727
import php.runtime.lang.Resource;
28-
import php.runtime.memory.ArrayMemory;
29-
import php.runtime.memory.LongMemory;
30-
import php.runtime.memory.ObjectMemory;
31-
import php.runtime.memory.StringMemory;
28+
import php.runtime.memory.*;
3229
import php.runtime.memory.helper.ObservableMemory;
3330
import php.runtime.reflection.*;
3431
import php.runtime.util.StackTracer;
@@ -413,9 +410,23 @@ public static boolean is_string(Memory memory) {
413410
return memory.isString();
414411
}
415412

413+
protected static Memory to_floating_point(String s) {
414+
try {
415+
return new DoubleMemory(Double.parseDouble(s));
416+
} catch(NumberFormatException nfe) {
417+
return null;
418+
}
419+
}
420+
416421
@Immutable
417422
public static boolean is_numeric(Memory memory) {
418-
return StringMemory.toNumeric(memory.toString(), false, null) != null;
423+
if (memory.isNumber()) {
424+
return true;
425+
} else {
426+
String asString = memory.toString();
427+
return StringMemory.toLong(asString, true) != null || to_floating_point(asString) != null;
428+
}
429+
//return StringMemory.toNumeric(memory.toString(), false, null) != null;
419430
}
420431

421432
@Immutable

0 commit comments

Comments
 (0)