Skip to content

Incorrect default value for methods in \Psr\Log\LoggerInterface #78

@ihor-sviziev

Description

@ihor-sviziev

Originally issue came from the Magento 2: magento/magento2#30575

We faced an issue with auto-generated proxy code based on the \Psr\Log\LoggerInterface.
Investigation shown that actually issue was caused by psr php extension - seems like default value isn't specified, while on original LoggerInterface we do have optional context argument wit default value - empty array.

Tested on php 7.3 and php 7.4, both versions having the same issue.

I was able to reproduce this issue even on a simple file (checked on emergency method, but issue the same for others):

<?php
include "./vendor/autoload.php";

$reflectionMethod = new \ReflectionMethod(\Psr\Log\LoggerInterface::class, "emergency");
$reflectionParameter = $reflectionMethod->getParameters()[1];
var_dump($reflectionParameter->isOptional());
var_dump($reflectionParameter->isDefaultValueAvailable());
var_dump($reflectionParameter->getDefaultValue());

and psr/log installed through composer.

Expected result

Result without psr extension

app@3bedbfa9e5db:~/html/pub$ php index.php 
bool(true)
bool(true)
array(0) {
}

Actual result

Result with psr extension

app@3bedbfa9e5db:~/html/pub$ php index.php 
bool(true)
bool(false)

Fatal error: Uncaught ReflectionException: Cannot determine default value for internal functions in /var/www/html/pub/index.php:8
Stack trace:
#0 /var/www/html/pub/index.php(8): ReflectionParameter->getDefaultValue()
#1 {main}
  thrown in /var/www/html/pub/index.php on line 8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions