Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbols are not found for safe 3.0 #617

Open
temp opened this issue Feb 12, 2025 · 7 comments
Open

Symbols are not found for safe 3.0 #617

temp opened this issue Feb 12, 2025 · 7 comments
Labels
question Further information is requested

Comments

@temp
Copy link

temp commented Feb 12, 2025

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?

@shish
Copy link
Collaborator

shish commented Feb 12, 2025

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
Copy link
Collaborator

shish commented Feb 12, 2025

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

@shish shish added the question Further information is requested label Feb 12, 2025
@temp
Copy link
Author

temp commented Feb 13, 2025

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...

@ballidev
Copy link

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

@shish
Copy link
Collaborator

shish commented Feb 13, 2025

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 #500 - tl;dr the current approach is ugly, but every other approach is worse D:

@shish
Copy link
Collaborator

shish commented Feb 13, 2025

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",
    ]
}

@temp
Copy link
Author

temp commented Feb 14, 2025

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        |
...

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

No branches or pull requests

3 participants