safe icon indicating copy to clipboard operation
safe copied to clipboard

Symbols are not found for safe 3.0

Open temp opened this issue 10 months ago • 9 comments

When using composer-require-checker with in a project with safe 3.0 I get these unknown symbols:

ComposerRequireChecker 4.16.1@2449a6298a0c39d940287d5d3afaf05a6f80fd0c
The following 16 unknown symbols were found:
+----------------------------+--------------------+
| Unknown Symbol             | Guessed Dependency |
+----------------------------+--------------------+
| Safe\date                  |                    |
| Safe\fclose                |                    |
| Safe\file_get_contents     |                    |
| Safe\file_put_contents     |                    |
| Safe\fopen                 |                    |
| Safe\fstat                 |                    |
| Safe\fwrite                |                    |
| Safe\json_encode           |                    |
| Safe\ob_end_clean          |                    |
| Safe\ob_start              |                    |
| Safe\phpinfo               |                    |
| Safe\preg_match            |                    |
| Safe\rewind                |                    |
| Safe\shuffle               |                    |
| Safe\stream_copy_to_stream |                    |
| Safe\stream_get_contents   |                    |
+----------------------------+--------------------+

When I switch back to 2.5 no unknown symbols are found. I tried to find the differences, but nothing obvious. Anyone know how to handle this?

temp avatar Feb 12 '25 11:02 temp

As a guess, is composer-require-checker grepping through the files listed in composer.json's autoload.files[] array, parsing them as strings, looking for function definitions? If it is, that won't work for safe 3.0 because the files listed in autoload are just stubs, and they import the real files (which differ based on PHP version) at runtime.

I wonder if there's a way to tell composer-require-checker "here is a list of files where our functions live", but without being in autoload (because we explicitly don't want all our files to be autoloaded)?

(If it's using some other mechanism then the solution would be completely different, I'm just making guesses about how composer-require-checker might work)

shish avatar Feb 12 '25 16:02 shish

Also perhaps there's something we could add to composer.json to indicate "this package is responsible for the entire Safe\ namespace"?

shish avatar Feb 12 '25 16:02 shish

composer-require-checker has a scan-file configuration directive, this works, but is clumsy as hell, since you have to add to it every time you use a new safe function from a new extension:

{
    "scan-files" : [
        "vendor/thecodingmachine/safe/generated/8.4/array.php",
        "vendor/thecodingmachine/safe/generated/8.4/datetime.php",
        "vendor/thecodingmachine/safe/generated/8.4/filesystem.php",
        "vendor/thecodingmachine/safe/generated/8.4/info.php",
        "vendor/thecodingmachine/safe/generated/8.4/json.php",
        "vendor/thecodingmachine/safe/generated/8.4/outcontrol.php",
        "vendor/thecodingmachine/safe/generated/8.4/pcre.php",
        "vendor/thecodingmachine/safe/generated/8.4/stream.php"
    ]
}

I don't know if there is something that can be defined on the composer-level...

temp avatar Feb 13 '25 07:02 temp

I wonder if you could actually make tagged releases or branches that discard this version checking and only include the correct code for that version directly in the generated file.

Then anyone with this issue (which would include me when I start using it) can just ensure they have the correct safe tag

Another option is that this library becomes simply a way to generate files directly in your own project. That might also allow for a much leaner codebase with only the required safe functions included - I wonder if this could be handled with rector somehow?

Just a bit of wondering in general really

ballidev avatar Feb 13 '25 17:02 ballidev

I wonder if you could actually make tagged releases or branches that discard this version checking and only include the correct code for that version directly in the generated file.

We had this discussion in https://github.com/thecodingmachine/safe/issues/500 - tl;dr the current approach is ugly, but every other approach is worse D:

shish avatar Feb 13 '25 21:02 shish

composer-require-checker has a scan-file configuration directive, this works, but is clumsy as hell, since you have to add to it every time you use a new safe function from a new extension:

The documentation suggests that you can use wildcards, so

{
    "scan-files" : [
        "vendor/thecodingmachine/safe/generated/8.4/*.php",
    ]
}

shish avatar Feb 13 '25 21:02 shish

The documentation suggests that you can use wildcards, so

{
    "scan-files" : [
        "vendor/thecodingmachine/safe/generated/8.4/*.php",
    ]
}

Sadly this doesn't work, tried this as I found my solution. When using the wildcard every unused function is printed as unknown. But I really don't know why... Here's an excerpt:

ComposerRequireChecker 4.16.1@2449a6298a0c39d940287d5d3afaf05a6f80fd0c
The following 918 unknown symbols were found:
+------------------------------------------------------+--------------------+
| Unknown Symbol                                       | Guessed Dependency |
+------------------------------------------------------+--------------------+
| AddressInfo                                          | ext-sockets        |
| apache_getenv                                        |                    |
| apache_get_version                                   |                    |
| apache_lookup_uri                                    |                    |
| apache_request_headers                               |                    |
| apache_response_headers                              |                    |
| apache_setenv                                        |                    |
| apcu_cache_info                                      |                    |
| apcu_cas                                             |                    |
| apcu_dec                                             |                    |
| apcu_inc                                             |                    |
| apcu_sma_info                                        |                    |
| bindtextdomain                                       | ext-gettext        |
...

temp avatar Feb 14 '25 07:02 temp

I ran into this issue too. Dunno why wildcards not working. I ended up manually adding every single file needed by my codebase - which fixed my issue with composer-require-checker:

    "scan-files" : [
        "vendor/thecodingmachine/safe/generated/8.1/array.php",
        "vendor/thecodingmachine/safe/generated/8.1/classobj.php",
        "vendor/thecodingmachine/safe/generated/8.1/datetime.php",
        "vendor/thecodingmachine/safe/generated/8.1/exec.php",
        "vendor/thecodingmachine/safe/generated/8.1/filesystem.php",
        "vendor/thecodingmachine/safe/generated/8.1/ftp.php",
        "vendor/thecodingmachine/safe/generated/8.1/info.php",
        "vendor/thecodingmachine/safe/generated/8.1/json.php",
        "vendor/thecodingmachine/safe/generated/8.1/mbstring.php",
        "vendor/thecodingmachine/safe/generated/8.1/openssl.php",
        "vendor/thecodingmachine/safe/generated/8.1/outcontrol.php",
        "vendor/thecodingmachine/safe/generated/8.1/pcre.php",
        "vendor/thecodingmachine/safe/generated/8.1/strings.php",
        "vendor/thecodingmachine/safe/generated/8.1/url.php"
    ],

mvhirsch avatar Apr 18 '25 15:04 mvhirsch

maybe its worth opening a issue on composer-require-checker

staabm avatar Apr 23 '25 08:04 staabm