# [PHP-CVS] Re:  Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_2/Zend/tests/bug51421.phpt branches/PHP_5_2/Zend/zend_compile.c branches/PHP_5_3/Zend/tests/bug51421.phpt branches/PHP_5_3/Zend/zend_compile.c trunk/Zend/tests/bug51421.phpt

- Thread: https://externals.io/message/48985
- Original archive: https://news-web.php.net/php.internals/48985
- Started by Etienne Kneuss on 2010-06-28T18:38:48+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #48985 — Etienne Kneuss — 2010-06-28T18:38:48+00:00

URL: https://externals.io/message/48985#48985

Hi,



> Hi!
>
>  1) arguments can be gathered dynamically in the function, using
> > […]
>
> Isn't it the case today?
>

It's the case at the time of the calls. But not when overriding a method:
class A { public function foo($a) { } }
class B extends A { public function foo() {} }
is considered invalid, but $obj->foo($arg); would be perfectly valid for
both objects.


> Maybe also we can add some syntax like:
> function foo($a, $b, ...) - where ... means "I'll deal with those arguments
> myself, ignore any compatibility checks" so if the prototype is
> foo($a,$b,$c) $a and $b would be checked but not $c and the function is
> considered to have enough args.
>

I'd find that syntax pretty explicit and easy to understand, it wouldn't
break any BC.


>
>  2) a child method should be allowed to define type hints in a
> > […]
>
> This needs to be fixed.
>
>  3) a child method should be allowed to return a ref even if the parent
> > […]
>
> This needs to be fixed too.
>
>  4) all in all: it shouldn't throw a fatal error, those are not critical
> > […]
>
> I'd say in general OO part of PHP seems to be much more strict and
> Java-like than the rest. I'm not sure it's good. I'd demote all situations
> where the engine has a way to proceed to at least warning level.
>

I don't believe that any of those checks causes difficulty for the engine,
especially considering that internal classes can pretty much to what they
want anyway.


>
>  I'd like to propose to relax such checks, by either allowing more (e.g. 1,
> > […]
>
> I think we shouldn't remove them - we should fix them. It doesn't seem to
> be too hard, IMHO.
>

Enforcing contra-variance can become a tad bit tricky when it comes to:
1) argument vs no argument
2) argument with/without null as default value
3) by ref or not (with/without default values)

We should probably specify it formally in which case a prototype is
accepted, and then see what needs to be fixed.

Also, checking for subtyping in PHP is O(n) which is "slow", but I don't
believe it's a concern big enough to change the way we implement
"instanceof".

Best,

-- 
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
>



-- 
Etienne Kneuss
http://www.colder.ch
