Git Product home page Git Product logo

Comments (2)

starfishpatkhoo avatar starfishpatkhoo commented on August 16, 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

from dice.

starfishpatkhoo avatar starfishpatkhoo commented on August 16, 2024

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]);

from dice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.