Hi internals!
This is a spinoff from the variadics thread. Quoting Stas:
I also think this:
public function query($query, ...$params)
public function query(...$params)
should be legal too.
This is a general issue in PHP that we might want to fix: Currently a
method A is not compatible with a method B if A has less arguments than B.
E.g. both of the following are incompatible signatures:
public function foo($bar)
public function foo()
public function foo($bar = NULL)
public function foo()
This doesn't really make sense. Removing parameters doesn't violate LSP,
because in PHP it is legal to pass more arguments than declared. (Only
adding additional required parameters would violate LSP.)
Is it okay to change this?
Thanks,
Nikita
This is a general issue in PHP that we might want to fix: Currently a
method A is not compatible with a method B if A has less arguments than B.E.g. both of the following are incompatible signatures:
public function foo($bar) public function foo() public function foo($bar = NULL) public function foo()
This doesn't really make sense. Removing parameters doesn't violate LSP,
because in PHP it is legal to pass more arguments than declared. (Only
adding additional required parameters would violate LSP.)Is it okay to change this?
Thanks,
Nikita
Patch for this change: https://github.com/php/php-src/pull/424
Nikita
I think of the following definition:
function foo($bar = NULL)
To really be two definitions with method overloading:
function foo()
function foo($bar)
Allowing an inheritor/implementor to choose to not implement the second
signature does not seem logical at all when you think of them this way. I'm
against this this proposal.
2013/8/29 Nikita Popov nikita.ppv@gmail.com:
Hi internals!
This is a spinoff from the variadics thread. Quoting Stas:
I also think this:
public function query($query, ...$params)
public function query(...$params)
should be legal too.
I respectfully disagree.
The first method requires at least one parameter (or two, depending on
the pending clarification in the other thread) , and the latest: zero
or more (or 1 or more).
This is a general issue in PHP that we might want to fix: Currently a
method A is not compatible with a method B if A has less arguments than B.E.g. both of the following are incompatible signatures:
public function foo($bar) public function foo() public function foo($bar = NULL) public function foo()
This doesn't really make sense. Removing parameters doesn't violate LSP,
because in PHP it is legal to pass more arguments than declared. (Only
adding additional required parameters would violate LSP.)Is it okay to change this?
I see no reason to do so and I would say -0.5.
Hi!
I respectfully disagree.
The first method requires at least one parameter (or two, depending on
the pending clarification in the other thread) , and the latest: zero
or more (or 1 or more).
Yes, this is true. But how it is an objection? LSP allows to weaken
preconditions, but not to strengthen them - that's exactly what happens.
Any method call that worked for base class would also work for derived
class, and some other, additional calls, would work too.
Is it okay to change this?
I see no reason to do so and I would say -0.5.
The reason is that current situation does not match LSP requirements and
serves no useful purpose. Especially the second one which literally has
the same preconditions but for some weird reason is rejected.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi internals!
This is a spinoff from the variadics thread. Quoting Stas:
I also think this:
public function query($query, ...$params)
public function query(...$params)
should be legal too.This is a general issue in PHP that we might want to fix: Currently a
method A is not compatible with a method B if A has less arguments than B.E.g. both of the following are incompatible signatures:
public function foo($bar) public function foo() public function foo($bar = NULL) public function foo()
This doesn't really make sense. Removing parameters doesn't violate LSP,
because in PHP it is legal to pass more arguments than declared. (Only
adding additional required parameters would violate LSP.)Is it okay to change this?
Thanks,
Nikita
Considering that we might support named parameters in the future I'm
withdrawing this suggestion. This allows removing a parameter name, which
would cause problems in that context.
Nikita
> Hi internals!
>
> This is a spinoff from the variadics thread. Quoting Stas:
>
> > I also think this:
> > public function query($query, ...$params)
> > public function query(...$params)
> > should be legal too.
>
> This is a general issue in PHP that we might want to fix: Currently a
> method A is not compatible with a method B if A has less arguments than B.
>
> E.g. both of the following are incompatible signatures:
>
> public function foo($bar)
> public function foo()
>
> public function foo($bar = NULL)
> public function foo()
>
I dont really agree.
One could use reflection on the parameter, thus expecting it to be here on
a child instance :
class Foo
{
public function bar($arg = null) { }
}
class Foo2 extends Foo
{
public function bar() { }
}
$o = new Foo; /* Switching to Foo2 will lead to an Exception */
$r = new ReflectionParameter(array($o, 'bar'), 'arg');
echo $r->getName();
PS : I remember having a long discussion with Gustavo, some time ago, about
LSP in PHP ; and we could not agree on some points, particularly concerning
optional parameters.
Julien.Pauli