Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Php85/Php85.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ public static function array_last(array $array)
{
return $array ? current(array_slice($array, -1)) : null;
}

public static function php_build_date()
{
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_clean();

preg_match('@Build Date(?:( => | </td><td class="v">))(?<buildtime>[A-Za-z]{3} (?: \d|\d\d) \d{4} \d{2}:\d{2}:\d{2})@', $info, $matches);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if preg_match returns false?


return $matches['buildtime'];
}
}
4 changes: 4 additions & 0 deletions src/Php85/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
return;
}

if(!defined('PHP_BUILD_DATE')){
define('PHP_BUILD_DATE', p\Php85::php_build_date());
}

if (!function_exists('get_error_handler')) {
function get_error_handler(): ?callable { return p\Php85::get_error_handler(); }
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Php85/Php85Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ public function testArrayFirstArrayLast()
$this->assertTrue(array_first([true, new \stdClass()]));
$this->assertEquals(new \stdClass(), array_last([true, new \stdClass()]));
}

public function testPhpBuildDate(){
$date = PHP_BUILD_DATE;
$this->assertMatchesRegularExpression(
'/^[A-Za-z]{3} \d{1,2} \d{4} \d{2}:\d{2}:\d{2}$/',
$date,
"The build date format is invalid: $date"
);
}
}

class TestHandler
Expand Down
Loading