Changeset 42130 for trunk/src/wp-includes/random_compat/cast_to_int.php
- Timestamp:
- 11/08/2017 11:47:04 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/random_compat/cast_to_int.php
r36886 r42130 6 6 * The MIT License (MIT) 7 7 * 8 * Copyright (c) 2015 Paragon Initiative Enterprises8 * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises 9 9 * 10 10 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 27 27 */ 28 28 29 if (! function_exists('RandomCompat_intval')) {29 if (!is_callable('RandomCompat_intval')) { 30 30 31 31 /** … … 39 39 * 40 40 * @param int|float $number The number we want to convert to an int 41 * @param bool ean$fail_open Set to true to not throw an exception41 * @param bool $fail_open Set to true to not throw an exception 42 42 * 43 * @return int (or float if $fail_open) 43 * @return float|int 44 * @psalm-suppress InvalidReturnType 44 45 * 45 46 * @throws TypeError … … 47 48 function RandomCompat_intval($number, $fail_open = false) 48 49 { 49 if (is_numeric($number)) { 50 if (is_int($number) || is_float($number)) { 51 $number += 0; 52 } elseif (is_numeric($number)) { 50 53 $number += 0; 51 54 } … … 61 64 } 62 65 63 if (is_int($number) || $fail_open) { 64 return $number; 66 if (is_int($number)) { 67 return (int) $number; 68 } elseif (!$fail_open) { 69 throw new TypeError( 70 'Expected an integer.' 71 ); 65 72 } 66 67 throw new TypeError( 68 'Expected an integer.' 69 ); 73 return $number; 70 74 } 71 75 }
Note: See TracChangeset
for help on using the changeset viewer.