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

constructParams being applied in the wrong order #181

Open
jpirnat opened this issue Mar 31, 2020 · 1 comment
Open

constructParams being applied in the wrong order #181

jpirnat opened this issue Mar 31, 2020 · 1 comment

Comments

@jpirnat
Copy link

jpirnat commented Mar 31, 2020

This appears to have started in version 4.0.2. When a rule contains 3 or more constructor parameters, the object is no longer initialized with the constructor parameters in the defined order.

Example (run on PHP 7.3.11 on a Mac):

<?php
declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

/** @var \Dice\Dice $dice */
$dice = new \Dice\Dice();

$rule = [
	'constructParams' => [
		'one',
		'two',
		'three',
		'four',
		'five',
		'six',
		'seven',
		'eight',
		'nine',
		'ten',
	]
];
$dice = $dice->addRule(Foo::class, $rule);

class Foo
{
	public function __construct(
		string $one,
		string $two,
		string $three,
		string $four,
		string $five,
		string $six,
		string $seven,
		string $eight,
		string $nine,
		string $ten
	) {
		print_r([$one, $two, $three, $four, $five, $six, $seven, $eight, $nine, $ten]);
	}
}

$foo = $dice->create(Foo::class);

Expected output (output in version 4.0.1):

Array
(
    [0] => one
    [1] => two
    [2] => three
    [3] => four
    [4] => five
    [5] => six
    [6] => seven
    [7] => eight
    [8] => nine
    [9] => ten
)

Actual output (output in version 4.0.2):

Array
(
    [0] => one
    [1] => three
    [2] => five
    [3] => seven
    [4] => nine
    [5] => two
    [6] => six
    [7] => ten
    [8] => four
    [9] => eight
)
denizozsen added a commit to denizozsen/Dice that referenced this issue Apr 30, 2020
…o next paramInfo element on finding a match
@cseufert
Copy link

I have merged a fix in a fork that I maintain:
https://github.com/moddengine/Dice

https://packagist.org/packages/moddengine/dice#v4.1.1

jtojnar added a commit to fossar/selfoss that referenced this issue Jun 15, 2023
Dice is nice but the code is showing its age (very dynamic) and
contains serious app breaking bugs like:
Level-2/Dice#181

Looking at other options on Packagist, skipping obviously abandoned or associated with the facade-infested framework:

- https://github.com/nette/di
  😡 container generator
  😡 too featureful
- https://github.com/symfony/dependency-injection
  🙂 native PSR-11
  😡 promotes configuration
- https://github.com/PHP-DI/PHP-DI
  🙂 nice docs
  😡 also too featureful
- https://github.com/auraphp/Aura.Di
  😡 verbose API
- https://github.com/ray-di/Ray.Di
  🙂 nice docs
  😡 “enterprise” API
- https://github.com/slince/di
  🙂 native PSR-11
  🙂 nice API
  😡 few unneeded features (aliases, parameters, tags)
- https://github.com/thephpleague/container
  🙂 native PSR-11
  🙂 nice API
  🙂 nice docs
  😡 even more unneeded features (inflectors)

After reviewing all of the above, I selected Slince’s DI library.
There were some bugs but they were quickly addressed upstream.
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