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

Trampoline autoloader will get reregistered and cannot be unregistered #10011

Closed
Girgias opened this issue Nov 28, 2022 · 0 comments
Closed

Trampoline autoloader will get reregistered and cannot be unregistered #10011

Girgias opened this issue Nov 28, 2022 · 0 comments

Comments

@Girgias
Copy link
Member

Girgias commented Nov 28, 2022

Description

Found while working on #8294, currently it is possible to register a trampoline as an autoloader but there is no way to remove it nor is it prevented from being registered multiple times.

The following code: https://3v4l.org/0mYUn

<?php

class TrampolineTest {
    public function __call(string $name, array $arguments) {
        echo 'Trampoline for ', $name, PHP_EOL;
    }
}
$o = new TrampolineTest();
$callback1 = [$o, 'trampoline1'];
$callback2 = [$o, 'trampoline2'];

spl_autoload_register($callback1);
spl_autoload_register($callback2);
spl_autoload_register($callback1); // 2nd call ignored

var_dump(spl_autoload_functions());

var_dump(class_exists("TestClass", true));

echo "Unregister trampoline:\n";
var_dump(spl_autoload_unregister($callback1));
var_dump(spl_autoload_unregister($callback1));
var_dump(spl_autoload_unregister($callback2));

var_dump(spl_autoload_functions());
var_dump(class_exists("TestClass", true));

Resulted in this output:

array(3) {
  [0]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline1"
  }
  [1]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline2"
  }
  [2]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline1"
  }
}
Trampoline for trampoline1
Trampoline for trampoline2
Trampoline for trampoline1
bool(false)
Unregister trampoline:
bool(false)
bool(false)
bool(false)
array(3) {
  [0]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline1"
  }
  [1]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline2"
  }
  [2]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline1"
  }
}
Trampoline for trampoline1
Trampoline for trampoline2
Trampoline for trampoline1
bool(false)

But I expected this output instead:

array(2) {
  [0]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline1"
  }
  [1]=>
  array(2) {
    [0]=>
    object(TrampolineTest)#1 (0) {
    }
    [1]=>
    string(11) "trampoline2"
  }
}
Trampoline for trampoline1
Trampoline for trampoline2
bool(false)
Unregister trampoline:
bool(true)
bool(false)
bool(true)
bool(false)

PHP Version

All

Operating System

No response

@Girgias Girgias self-assigned this Nov 28, 2022
Girgias added a commit to Girgias/php-src that referenced this issue Dec 2, 2022
…ot be unregistered)

There are two issues to resolve:
 1. The FCC is not refetch when trying to unregister a trampoline
 2. Comparing the function pointer of trampolines is meaningless as they are reallocated, thus we need to compare the name of the function

Found while working on phpGH-8294
@Girgias Girgias closed this as completed in 608ddb0 Dec 2, 2022
Girgias added a commit that referenced this issue Dec 2, 2022
* PHP-8.1:
  Fix GH-10011 (Trampoline autoloader will get reregistered and cannot be unregistered)
Girgias added a commit that referenced this issue Dec 2, 2022
* PHP-8.2:
  Fix GH-10011 (Trampoline autoloader will get reregistered and cannot be unregistered)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
@Girgias and others