Git Product home page Git Product logo

Comments (11)

cseufert avatar cseufert commented on July 17, 2024 4

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.

vaclavgreif avatar vaclavgreif commented on July 17, 2024 2

@TRPB Any chance to add this to core? Using PHP8 on some projects already.

from dice.

jtojnar avatar jtojnar commented on July 17, 2024 1

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.

cseufert avatar cseufert commented on July 17, 2024 1

@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.

cseufert avatar cseufert commented on July 17, 2024 1

@jpirnat This is now fixed in 4.1.3

from dice.

StuTheBearded avatar StuTheBearded commented on July 17, 2024

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.

cseufert avatar cseufert commented on July 17, 2024

Although this patch will work for single class parameters, any Union types will cause an error on this line.

from dice.

hallleron avatar hallleron commented on July 17, 2024

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.

jpirnat avatar jpirnat commented on July 17, 2024

@cseufert Could you apply the fix in #183 to your fork?

from dice.

jpirnat avatar jpirnat commented on July 17, 2024

@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.

jtojnar avatar jtojnar commented on July 17, 2024

This has been fixed in 4.0.3: https://github.com/Level-2/Dice/releases/tag/4.0.3

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.