[Server] Add autoload check for enum types in ReferenceHandler#225
[Server] Add autoload check for enum types in ReferenceHandler#225joshuatam wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Some old framework is using autoload to include with the typeName directly, e.g. `include(ini.php)` when the typeName is `ini`. If the typeName is the arbitrary type, set autoload in `enum_exists` to `false`
|
Hey @joshuatam, thanks for reaching out and bringing the patch. Can you help me understand the issue here? What's happening without this patch? |
I am integrating the sdk with Yii1, in which it will throw an error when reading Elements classes, e.g. And the error is |
|
I'm really not sure that this is an error on library side, but rather something your autoloader should catch? are you using composer or sth custom? |
| $shouldAutoload = !in_array($typeName, ['int', 'float', 'string', 'bool', 'array', 'object', 'callable', 'iterable', 'mixed', 'void', 'null', 'false', 'true', 'never']); | ||
|
|
||
| if (enum_exists($typeName, $shouldAutoload)) { |
There was a problem hiding this comment.
Can we do something like this?
Ie, if it is an int, we would never call enum_exists().
| $shouldAutoload = !in_array($typeName, ['int', 'float', 'string', 'bool', 'array', 'object', 'callable', 'iterable', 'mixed', 'void', 'null', 'false', 'true', 'never']); | |
| if (enum_exists($typeName, $shouldAutoload)) { | |
| if ($type->isBuiltin() === false && enum_exists($typeName)) { |
https://www.php.net/manual/en/language.types.type-system.php
Motivation and Context
Some old framework is using autoload to include with the typeName directly, e.g.
include(ini.php)when the typeName isini.If the typeName is the arbitrary type, set autoload in
enum_existstofalseHow Has This Been Tested?
Yes
Breaking Changes
No
Types of changes
Checklist
Additional context
None