Comments (2)
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.
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)
- constructParams being applied in the wrong order HOT 1
- Error in documentation about json loading
- Wildcards in rules HOT 3
- Can't inherit global rules HOT 1
- Shared chain call HOT 8
- Call to undefined method ReflectionType::getName() HOT 3
- How to share a substitution HOT 1
- PHP 8 Deprecation HOT 11
- ..
- How to deal with inheritance HOT 2
- Having trouble creating PDO object HOT 3
- Performance: Opcache and Compiled container
- Support for union/intersection types? HOT 2
- Website section 4.1 missing.
- How to get a named instance from the container? HOT 1
- shareInstances are resolving but don't always propagate
- shared dependencies not working HOT 2
- PDO or Mysqli, named instances and shared instances error Undefined Array Key
- Shared dependencies by default? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dice.