Skip to content

phpversion fact may come out empty #769

Open

Description

@tobixen

Disclaimer: AI-generated text below the line, generated by Claude Opus 5. The issue was found (by Claude) while working with pull request #768

Having the AI generate issues is cheap, reading and understanding them is not. I respect that some maintainers may want to close AI-generated issues without spending time on explaining why.


Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: openvox 8 (Gemfile range >= 7, < 9)
  • Ruby: 3.4.10
  • Facter: 5.7.0
  • Distribution: any
  • Module version: master (12.0.1-rc0)

How to reproduce (e.g Puppet code you use)

The fact parses the first line of php -v only:

https://github.com/voxpupuli/puppet-php/blob/master/lib/facter/phpversion.rb

A php that emits a startup warning writes it to stdout before the version banner. A php on $PATH behaving like this is enough:

#!/bin/sh
echo "PHP Warning:  Module 'imagick' already loaded in Unknown on line 0"
echo "PHP 8.2.7 (cli) (built: Jun  8 2023 20:03:25) (NTS)"
echo "Copyright (c) The PHP Group"

What are you seeing

php on PATH: "/.../php"
php -v first line: "PHP Warning:  Module 'imagick' already loaded in Unknown on line 0"
phpversion fact:   nil

The fact resolves to nothing, silently — no version, no warning, no error in the log. Anything keying on $facts['phpversion'] sees an absent fact on a node where php is installed and working.

What behaviour did you expect instead

8.2.7, as on a node whose php starts cleanly. Scanning the whole output rather than the first line would do it, e.g. output[%r{^PHP (\d+\.\d+\.\d+\S*)}, 1] (^ is already per-line in Ruby).

Output log

No log output at all — that is part of the problem; the failure is silent.

Any additional information you'd like to impart

Pre-existing and unrelated to #768, which is about the fact raising when php is absent; that PR does not touch the parsing.

Two smaller things noticed in the same line, not worth their own issues:

  • An RC build reports as 8.4.0RC1, since the match keeps the whole token. Probably wanted, but worth knowing.
  • The regex %r{^(?:(\d+)\.)(?:(\d+)\.)?(\*|\d+)} has three capture groups nothing reads, and the \* alternative cannot match php -v output.

Activity

  1. tobixen commented on Sep 18, 2026

    @tobixen
    Author

    I pushed Claude Opus a bit with this one:

    Was any testing done while creating the issue report?

    So now this has been tested with actual PHP 8.2.33. The bug has been confirmed, but also narrowed down the problem to the land of "corner cases that we may not care about".

    Real php does write startup warnings to stdout before printing the version banner. Feeding the exact bytes of a real php -v into the fact caused a nil value to be returned. This is the real output observed:

    $ php -v 2>/dev/null | cat -A | head -3
    $
    Warning: Module "sodium" is already loaded in Unknown on line 0$
    PHP 8.2.33 (cli) (built: Sep 15 2026 21:32:37) (NTS)$
    

    The research also found it to be a quite narrow corner case, most likely not going to hit a lot of production systems nor common distro packages. It depends on display_errors for the CLI SAPI:

    config php -v stdout fact
    no php.ini (official php:8.2-cli image) warning first nil
    php.ini-development (display_errors=On) warning first nil
    php.ini-production (display_errors=Off) clean 8.2.33
    Debian/Ubuntu packaged php-cli clean — warning goes to stderr works

    ... so it may not be worth fixing, but scanning the whole output instead of the first line would still be a cheap fix.

    (Disclaimer: text above is a human rewrite of a longer Claude-generated text. I may be wrong, but I believe I'm still better than Claude on this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions