Skip to content

Symbols are not found for safe 3.0 #617

Description

@temp

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?

Activity

  1. shish commented on Feb 12, 2025

    @shish
    Collaborator

    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)

  2. shish commented on Feb 12, 2025

    @shish
    Collaborator

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

  3. temp commented on Feb 13, 2025

    @temp
    Author

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

  4. ballidev commented on Feb 13, 2025

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

    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

  5. shish commented on Feb 13, 2025

    @shish
    Collaborator

    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:

  6. shish commented on Feb 13, 2025

    @shish
    Collaborator

    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",
        ]
    }
    
  7. temp commented on Feb 14, 2025

    @temp
    Author

    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        |
    ...
    
  8. mvhirsch commented on Apr 18, 2025

    @mvhirsch
    Contributor

    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"
        ],
  9. staabm commented on Apr 23, 2025

    @staabm
    Collaborator

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

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

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions