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

Fatal error: Uncaught TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, function "is_mixed" not found. #210

Open
CarlosCardenasNegro opened this issue Apr 6, 2024 · 2 comments

Comments

@CarlosCardenasNegro
Copy link

A new variable type was introduced in PHP 8.0.0 aka "mixed". When one of the variables in the class constructor is of type "mixed" DICE tries to construct the argument of the function 'call_user_func()' for test this arguments and obtains "is_mixed" which, obviously, does not exist yet in PHP and there, I think the error arises.

I don't have enough PHP knowledge to create a fork but someone with more knowledge could probably resolve this issue easily.

(sorry, google translate)

@starfishpatkhoo
Copy link

starfishpatkhoo commented Apr 13, 2024

Okie, I think I have a problem that is very similar to yours. Something like ...

class ToBeInjected {
	function __contruct (ClassToInject $a, string|array|null $b = null) {
		$a ...
		$b ...
		blah blah blah
	}
}

$dice->create("ToBeInjected", [$incoming_b]);

When the class ToBeInjected is created, Dice will exception at Dice.php line 257, Call to undefined method ReflectionUnionType::getName()

If you change $b to be only string or only array or even ?string or ?array it works just fine. Trying to set up a constructParams rule doesn't work either. So I can only conclude that Dice's ability to figure out the arguments does not work for these types of types ...

So new it yourself (instead of $dice->create()), or change your params to be more precise...

Just FYI, in my use case, it makes sense because the input is EITHER a string, or an array, and for each case we handle things slightly differently. Having the input to be string|array makes sure (forces) that we have only one input, and not end up a situation where we were given both a string and an array and have to choose between one or the other.

PS. PHP 8.1, Dice 4.0.4

@starfishpatkhoo
Copy link

Sorry, just wanted to add on another case for FYI:

class ToBeInjected {
	function __contruct (ClassInject $a, ?array $b = null, ?string $c = null) {
		$a ...
		$b ...
		$c ...
		blah blah blah
	}
}

$dice->create("ToBeInjected", [null, $incoming_c]);

This does NOT work. You need to do:

$dice->create("ToBeInjected", [array(), $incoming_c]);

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

No branches or pull requests

2 participants