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

PHP 8.0+ changes behaviour of ReflectionClass::newInstanceArgs #193

Closed
wants to merge 1 commit into from

Conversation

marcing
Copy link
Contributor

@marcing marcing commented Feb 5, 2024

PHP 8.0+ changes behaviour of ReflectionClass::newInstanceArgs, which now assumes that an associative array is an array of named parameters, trying to match array keys to names of arguments in the constructor. This leads to errors like:

zend-form\library\Zend\Form\Element.php:2117
Error: Unknown named parameter $type

To solve the issue for all PHP versions, associative arrays have to be wrapper in array_values(). This does not concern cases where ReflectionClass::newInstanceArgs is used with numerical arrays.

Issue and solution can be tested on all PHP versions with this simple script:

<?php

class Test
{
	public $options;

	public function __construct(array $options)
	{
		$this->options = $options;
	}
}

$options = array('options' => array('tags' => array(1, 2, 3)));

$reflectionClass = new ReflectionClass('Test');
$instance = $reflectionClass->newInstanceArgs(array_values($options));

var_dump($instance->options);

@marcing marcing closed this Feb 5, 2024
@marcing marcing deleted the fix/php8-zend-form-element branch February 13, 2024 13:48
@marcing marcing removed the request for review from falkenhawk February 13, 2024 17:02
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

Successfully merging this pull request may close these issues.

1 participant