Comments (11)
If anyone is interested, I am now maintaining a fork here with PHP 8 support:
https://packagist.org/packages/moddengine/dice#v4.1.0
from dice.
@TRPB Any chance to add this to core? Using PHP8 on some projects already.
from dice.
It needs to be
if (PHP_VERSION_ID < 70100) {
// getClass is deprecated in PHP 8.0 but getType() does not support getName() before 7.1.
$class = $param->getClass() ? $param->getClass()->name : null;
} else {
$class = $param->getType() && !$param->getType()->isBuiltin() && $param->getType() instanceof \ReflectionNamedType ? $param->getType()->getName() : null;
}
Works in PHP 7.0 as well as 8.0: https://3v4l.org/qRavH
from dice.
@jpirnat
I have added that fix, and also added tests for that case
https://github.com/moddengine/Dice/releases/tag/v4.1.1
from dice.
@jpirnat This is now fixed in 4.1.3
from dice.
Here is my fix for that error message, replace line 216 with the below:
$class = $param->getType() && !$param->getType()->isBuiltin() ? $param->getType()->getName() : null;
from dice.
Although this patch will work for single class parameters, any Union types will cause an error on this line.
from dice.
Although this patch will work for single class parameters, any Union types will cause an error on this line.
Yes exactly, I haven't yet been able to figure out a workaround.
from dice.
@cseufert Could you apply the fix in #183 to your fork?
from dice.
@cseufert Your fork breaks Dice named instances from v4.1.0 onward, at least for PDO.
Test script:
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
$dice = new \Dice\Dice();
$host = '127.0.0.1';
$port = '3306';
$name = 'schema_name';
$user = 'username_here';
$pass = 'password_here';
$rule = [
'constructParams' => [
"mysql:host=$host;port=$port;dbname=$name;charset=utf8mb4",
$user,
$pass,
[
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]
],
'shared' => true,
];
$dice = $dice->addRule(PDO::class, $rule);
$rule = [
'instanceOf' => PDO::class,
'constructParams' => [
"mysql:host=$host;port=$port;dbname=$name;charset=utf8mb4",
$user,
$pass,
[
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]
],
'shared' => true,
];
$dice = $dice->addRule('$database2', $rule);
$database1 = $dice->create(PDO::class);
$database2 = $dice->create('$database2');
var_dump($database1);
var_dump($database2);
Tests run with PHP v7.4.2 on a Mac with MAMP v5.7
Output with level-2/dice v4.0.2 and moddengine/dice v4.0.2:
object(PDO)#12 (0) {
}
object(PDO)#22 (0) {
}
Output with moddengine/dice v4.1.0
Notice: Undefined index: $database2 in /Users/jesse/dicetest/vendor/moddengine/dice/Dice.php on line 140
object(PDO)#12 (0) {
}
NULL
Output with moddengine/dice v4.1.1:
Notice: Undefined index: $database2 in /Users/jesse/dicetest/vendor/moddengine/dice/Dice.php on line 216
object(PDO)#12 (0) {
}
NULL
I would leave this as an issue directly on your fork, but uhh, that's not an option, so here it is instead.
from dice.
This has been fixed in 4.0.3: https://github.com/Level-2/Dice/releases/tag/4.0.3
from dice.
Related Issues (20)
- shared instances HOT 12
- 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
- ..
- 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.