Skip to content

Conversation

arshidkv12
Copy link

Provide a polyfill for the PHP_BUILD_DATE constant (added in PHP 8.5).

  • Define PHP_BUILD_DATE if not already defined, using Php85::php_build_date()
  • Introduce php_build_date() helper to extract the build timestamp from phpinfo()
  • Add PHPUnit test to ensure the helper returns a valid and parseable build date string

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?

$this->assertEquals(new \stdClass(), array_last([true, new \stdClass()]));
}

public function testPhpBuildDate()
Copy link
Member

Choose a reason for hiding this comment

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

based on docs of phpinfo , would be good to run (or mock the run) under:

  • cli
  • webserver
  • webserver with expose_php configuration setting is set to off

@OskarStark OskarStark changed the title PHP 8.5 - add PHP_BUILD_DATE constant PHP 8.5 - add PHP_BUILD_DATE constant Sep 8, 2025
@nicolas-grekas
Copy link
Member

I'm going to save us all some time: this cannot be polyfilled efficiently.

The polyfill relies on running some non-trivial code for everysingle requests, to populate a const that's going to be needed very few times.

That's not worth the perf (and CO2) impact !

Thanks for your understanding.

@arshidkv12
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants