Skip to content

[RFC] Autoloading functions #15471

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

Closed
wants to merge 27 commits into from

Conversation

withinboredom
Copy link
Member

@withinboredom withinboredom commented Aug 17, 2024

This PR implements the function autoload v4 RFC.

Key overview:

  1. An additional parameter is added to spl_autoload_register to allow registering functions to load functions and/or classes. This involves two new constants: SPL_AUTOLOAD_CLASS and SPL_AUTOLOAD_FUNCTION.
  2. Significant changes to zend_execute.c and zend_execute.h to implement autoloading of functions.
  3. The addition of a new helper function: zend_locate_function which searches the function table before performing an autoload. It returns the zval of the function, or NULL. It can be used as a drop-in replacement for looking up a function in the function table directly.
  4. Additional changes to the SPL library, as documented in the RFC.
  5. New tests that ensure the RFC is implemented correctly.

Note before merging: Symfony has some code that is broken by this change. I've updated the benchmark loader to point to my fork of the benchmarks. As you can see the changes are very minimal.

Note: this does not include potential changes to opcache's JIT, which may need changes in zend_jit_find_func_helper, zend_jit_jmp_frameless_helper, and zend_jit_find_ns_func_helper

@withinboredom withinboredom marked this pull request as draft August 17, 2024 16:54
@withinboredom withinboredom marked this pull request as ready for review August 18, 2024 20:04
@withinboredom withinboredom changed the title [RFC][WIP] Autoloading functions [RFC] Autoloading functions Aug 18, 2024
@withinboredom
Copy link
Member Author

I do not have an ARM machine to test this PR on. Can someone potentially get the logs for the failing tests?

@iluuu1994
Copy link
Member

Possibly, the job isn't failing because of arm, but because of the test flags. Namely:

  -d opcache.enable_cli=1 \
  -d opcache.jit_buffer_size=64M \
  -d opcache.jit=tracing \
  -d zend_test.observer.enabled=1 \
  -d zend_test.observer.show_output=0 \
  --repeat 2

@withinboredom
Copy link
Member Author

@iluuu1994, looks like a bug with opcache?

The error is:

Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script

and the script is:

namespace {
    spl_autoload_register(function(string $name, int $mode) {
        echo "name=$name, mode=$mode\n";
    }, true, false, SPL_AUTOLOAD_FUNCTION);
}

namespace Foo {
    echo strlen('foo') . "\n";
}

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

Successfully merging this pull request may close these issues.

2 participants