Bug #71428 [Opn->Ver]: Validation type inheritance with = NULL

From: Date: Mon, 28 Mar 2016 07:14:32 +0000
Subject: Bug #71428 [Opn->Ver]: Validation type inheritance with = NULL
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200175@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71428&edit=1

 ID:                 71428
 Updated by:         krakjoe@php.net
 Reported by:        dpa-bugs at aegee dot org
 Summary:            Validation type inheritance with = NULL
-Status:             Open
+Status:             Verified
 Type:               Bug
 Package:            Class/Object related
 PHP Version:        7.0.2
 Block user comment: N
 Private report:     N

 New Comment:

There are bugs in 

 * zend_do_perform_type_hint_check (never verifies compatibility of zend_arg_info.allow_null) 
 * zend_get_function_declaration

The bugs in zend_get_function_declaration are because we make this assumption: 

    if (i >= required && !arg_info->is_variadic)

So do not generate the correct error message when you fix the type hint check.

It's 8am on Monday morning ... someone else should have a go ...


Previous Comments:
------------------------------------------------------------------------
[2016-03-23 21:20:22] dpa-bugs at aegee dot org

In all examples, you cannot pass NULL as first parameter to the derived m(), but you can bass NULL
as first parameter to parent::m().  So the method signature changes, in terms of possible values
that can be supplied.

------------------------------------------------------------------------
[2016-03-23 17:05:18] danielgarthsims at gmail dot com

Is this a bug? I don't see why it's a problem. Looking at the nikic's example, the
method signature doesn't change, just the default value for the method.

In the original example, you're still requiring two variables, but the second one can no longer
be null. I'm not sure what the expected behavior should be.

------------------------------------------------------------------------
[2016-01-21 22:10:10] dpa-bugs at aegee dot org

By the way, I do not write = NULL, because I want the argument to be optional.  I write it, in order
to be able to pass NULL as parameter.

------------------------------------------------------------------------
[2016-01-21 21:23:18] nikic@php.net

Another example that does not rely on optional-before-required arguments:

class A {
    public function m(array $a = null) {}
}
class B extends A {
    public function m(array $a = []) {}
}

------------------------------------------------------------------------
[2016-01-21 18:52:48] dpa-bugs at aegee dot org

Description:
------------
<?php
class A { }
class B           {  public function m(A $a = NULL, $n) { echo "B.m";} };
class C extends B {  public function m(A $a       , $n) { echo "C.m";} };
$b = new B();
$b->m(new A(), $b);
$c = new C();
$c->m(new A(), $b);
?>

reports nothing, but shall report:

PHP Warning:  Declaration of C::m(A $a, $n) should be compatible with B::m(A $a = NULL, $n) on line
4


Removing on both places $n reports correctly:

PHP Warning:  Declaration of C::m(A $a) should be compatible with B::m(A $a = NULL) on line 4

Same with php 5.6.17.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71428&edit=1


Thread (11 messages)

« previous php.bugs (#200175) next »