Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d28746
commit 882c01c
Showing
6 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* PHP Polyfill | ||
* | ||
* @author Greg Roach <fisharebest@gmail.com> | ||
* @copyright (c) 2016 Greg Roach | ||
* @license MIT or GPLv3+ | ||
*/ | ||
|
||
namespace Fisharebest\PhpPolyfill; | ||
|
||
use Symfony\Polyfill\Php54\Php54 as SymfonyPhp54; | ||
|
||
/** | ||
* Class Php - polyfills for poor implementations of PHP | ||
*/ | ||
class Php { | ||
const BIG_ENDIAN_INF_BYTES = '7ff0000000000000'; | ||
const LITTLE_ENDIAN_INF_BYTES = '000000000000f07f'; | ||
|
||
/** | ||
* Some builds of PHP (e.g. strato.de on SunOS) omit the | ||
* definition of INF. | ||
* | ||
* Note: we can't use hex2bin() on PHP 5.3. Use pack('H*') instead. | ||
* | ||
* @link http://php.net/manual/en/math.constants.php | ||
* | ||
* @return double | ||
*/ | ||
public static function inf() { | ||
$inf_bytes = self::isLittleEndian() ? self::LITTLE_ENDIAN_INF_BYTES : self::BIG_ENDIAN_INF_BYTES; | ||
$inf = unpack('d', pack('H*', $inf_bytes)); | ||
|
||
return $inf[1]; | ||
} | ||
|
||
|
||
/** | ||
* Is this CPU big-endian or little-endian? | ||
* | ||
* @return bool | ||
*/ | ||
private static function isLittleEndian() { | ||
$tmp = unpack('S',"\x01\x00"); | ||
|
||
return $tmp[1] === 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* PHP Polyfill | ||
* | ||
* @author Greg Roach <fisharebest@gmail.com> | ||
* @copyright (c) 2016 Greg Roach | ||
* @license MIT or GPLv3+ | ||
*/ | ||
|
||
namespace Fisharebest\PhpPolyfill\Test; | ||
|
||
use Fisharebest\PhpPolyfill\Php; | ||
use PHPUnit_Framework_Error_Warning; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
/** | ||
* Class PhpTest - tests for class Php | ||
*/ | ||
class PhpTest extends PHPUnit_Framework_TestCase { | ||
/** | ||
* @covers Fisharebest\PhpPolyfill\Php::inf | ||
* @covers Fisharebest\PhpPolyfill\Php::isLittleEndian | ||
* @runInSeparateProcess | ||
*/ | ||
public function testInf() { | ||
$this->assertTrue(is_float(Php::inf())); | ||
$this->assertTrue(is_double(Php::inf())); | ||
$this->assertTrue(is_infinite(Php::inf())); | ||
$this->assertFalse(is_finite(Php::inf())); | ||
} | ||
} |