php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73105 ReflectionParameter returns nullable type when one is not used
Submitted: 2016-09-18 12:08 UTC Modified: 2016-10-01 14:39 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:0 (0.0%)
From: mail at ciaranmcnulty dot com Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 7.1.0RC2 OS: OSX
Private report: No CVE-ID: None
 [2016-09-18 12:08 UTC] mail at ciaranmcnulty dot com
Description:
------------
Reflection normalises typehints on parameters with defaults of null to be Nullable typehints.

This is a change of behaviour and caused issues in Prophecy (Mocking library) and probably other tools that lean on reflection. It's not appropriate for a minor version number.

Test script:
---------------
function foo(Bar $bar = null){}

echo ((new ReflectionFunction('foo'))->getParameters()[0]->getType());

Expected result:
----------------
output 'Bar'

Actual result:
--------------
output '?Bar'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-18 16:19 UTC] cmb@php.net
Related discussion: <http://marc.info/?t=147145076000010&r=1&w=2>.
 [2016-09-18 18:02 UTC] mail at ciaranmcnulty dot com
Thanks for the context, it seems like the conversation ends with opposing views but not much resolution.

From my perspective, code written under 7.0 that isn't using 7.1 features is no longer behaving the way it used to. 

How can this be correct BC policy?
 [2016-10-01 14:39 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 01:01:33 2024 UTC