# E_STRICT on inheritance + method parameter defaults?

- Thread: https://externals.io/message/19110
- Original archive: https://news-web.php.net/php.internals/19110
- Started by Sean Coates on 2005-09-21T14:54:31+00:00
- Messages: 5
- 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

---

## #19110 — Sean Coates — 2005-09-21T14:54:31+00:00

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

Hello all,

This crept up as the result of a bug report (not mine --
http://bugs.php.net/34494), and a small discussion on IRC:

Why does an `E_STRICT` get raised when extending a class, and altering the
method's proto defaults? I understand why it would be thrown when
adding/changing parameters, but why when simply changing $foo to $foo=1 ?

Honest question -- I'm not trying to change the behavior, here. It
doesn't seem "correct" to me, but I look forward to an explanation that
I've simply overlooked.

S

---

## #19111 — Marcus Boerger — 2005-09-21T17:30:02+00:00

URL: https://externals.io/message/19110#19111 · In reply to: #19110

Hello Sean,

Wednesday, September 21, 2005, 4:54:31 PM, you wrote:

> Hello all,

> This crept up as the result of a bug report (not mine --
> http://bugs.php.net/34494), and a small discussion on IRC:

> Why does an `E_STRICT` get raised when extending a class, and altering the
> method's proto defaults? I understand why it would be thrown when
> adding/changing parameters, but why when simply changing $foo to $foo=1 ?

> Honest question -- I'm not trying to change the behavior, here. It
> doesn't seem "correct" to me, but I look forward to an explanation that
> I've simply overlooked.

> S


marcus@zaphod /usr/src/PHP_5_1 $ php -r 'class T{function f($x){}} class U extends T{function f($x=2){}}'
make: `sapi/cli/php' is up to date.

Strict Standards: Declaration of U::f() should be compatible with that of T::f() in Command line code on line 1
marcus@zaphod /usr/src/PHP_5_1 $ php -r 'class T{function f($x=1){}} class U extends T{function f($x=2){}}'
make: `sapi/cli/php' is up to date.

The above shows php is correct here.

Best regards,
 Marcus

---

## #19112 — Christian Schneider — 2005-09-21T20:37:01+00:00

URL: https://externals.io/message/19110#19112 · In reply to: #19111

Marcus Boerger wrote:
> marcus@zaphod /usr/src/PHP_5_1 $ php -r 'class T{function f($x){}} class U extends T{function f($x=2){}}'
> make: `sapi/cli/php' is up to date.
> 
> Strict Standards: Declaration of U::f() should be compatible with that of T::f() in Command line code on line 1
> marcus@zaphod /usr/src/PHP_5_1 $ php -r 'class T{function f($x=1){}} class U extends T{function f($x=2){}}'
> make: `sapi/cli/php' is up to date.
> 
> The above shows php is correct here.

In my opinion Sean didn't ask whether PHP behaves that way but _why_.

And I don't really see the point either as U::f works with all code 
previously using T::f. Even more so for function V::f($x,$y=false) to 
provide extended functionality to T::f($x) for code which knows about 
it.  And why would changing the default value be ok in your book? But 
then again I'm not an OO purist and I don't (have to) use E_STRICT.

- Chris

---

## #19113 — Christian Schneider — 2005-09-21T20:39:48+00:00

URL: https://externals.io/message/19110#19113 · In reply to: #19112

Christian Schneider wrote:
> Even more so for function V::f($x,$y=false) to 
> provide extended functionality to T::f($x) for code which knows about it

Ok, forget that part, I made a typo when testing this ;-)

Apologies,
- Chris

---

## #19114 — Marcus Boerger — 2005-09-21T22:28:07+00:00

URL: https://externals.io/message/19110#19114 · In reply to: #19112

Hello Christian,

Wednesday, September 21, 2005, 10:37:01 PM, you wrote:

> Marcus Boerger wrote:
> > […]

> In my opinion Sean didn't ask whether PHP behaves that way but _why_.

The above example show that adding a default result value in a derived class
results in an incompatible signature while changing it works as expected.


Best regards,
 Marcus
