Resurrected "legendary" function bigintval() from mailer 0.2.1-FINAL code with some...
authorRoland Häder <roland@mxchange.org>
Wed, 21 Mar 2012 22:00:17 +0000 (22:00 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 21 Mar 2012 22:00:17 +0000 (22:00 +0000)
inc/classes/main/class_BaseFrameworkSystem.php

index 15040a6b17645b45347c59a2b5123b3270a3b74d..255a7f614352ed8c6580a2e32019da200a248296 100644 (file)
@@ -1988,6 +1988,31 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return it
                return $hash;
        }
+
+       /**
+        * Checks whether the given number is really a number (only chars 0-9).
+        *
+        * @param       $num            A string consisting only chars between 0 and 9
+        * @param       $castValue      Whether to cast the value to double. Do only use this to secure numbers from Requestable classes.
+        * @param       $assertMismatch         Whether to assert mismatches
+        * @return      $ret            The (hopefully) secured numbered value
+        */
+       public function bigintval ($num, $castValue = true, $assertMismatch = false) {
+               // Filter all numbers out
+               $ret = preg_replace('/[^0123456789]/', '', $num);
+
+               // Shall we cast?
+               if ($castValue === true) {
+                       // Cast to biggest numeric type
+                       $ret = (double) $ret;
+               } // END - if
+
+               // Has the whole value changed?
+               assert(($assertMismatch === true) && ('' . $ret . '' != '' . $num . '') && (!is_null($num)));
+
+               // Return result
+               return $ret;
+       }
 }
 
 // [EOF]