Bug #62537 [Com]: Composed class has fatal error with duplicate, equal array properties

From: Date: Sun, 15 Sep 2013 01:27:48 +0000
Subject: Bug #62537 [Com]: Composed class has fatal error with duplicate, equal array properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-181584@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62537&edit=1

 ID:                 62537
 Comment by:         metamarkers at gmail dot com
 Reported by:        jeremeamia at gmail dot com
 Summary:            Composed class has fatal error with duplicate, equal
                     array properties
 Status:             Open
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Ubuntu
 PHP Version:        5.4.4
 Block user comment: N
 Private report:     N

 New Comment:

This is a bug. It should not a be a fatal error if the initial value is even the 
same **type**. Consider using traits to define default static vars. Defining them 
through inheritance, these static vars are clobbered unless explicitly redefined 
in every child class.

It makes perfect sense not to allow this with constants, but why static 
variables?


Previous Comments:
------------------------------------------------------------------------
[2012-10-26 19:09:49] dagguh at gmail dot com

If it is logically the same thing, it should be only in one of these traits, don't 
you think?
SRP and DRY, fellas

------------------------------------------------------------------------
[2012-07-20 09:07:13] aharvey@php.net

I'd call this a bug, rather than a documentation issue; if Foo::$var === Bar::$var, I
can't really see why it should fatal.

Reclassifying, and we'll see what the engine folk think.

------------------------------------------------------------------------
[2012-07-12 01:36:55] jeremeamia at gmail dot com

Another test script, which might be even more relevant:

  trait Foo {public $var = [];}
  class Bar {use Foo; public $var = [];}

This also causes a fatal error for me, which should only be a strict error based 
on the documentation.

------------------------------------------------------------------------
[2012-07-11 19:45:00] jeremeamia at gmail dot com

Description:
------------
---
From manual page: http://www.php.net/language.oop5.traits
---

The manual says, "If a trait defines a property then a class can not define a 
property with the same name, otherwise an error is issued. It is an E_STRICT if 
the class definition is compatible (same visibility and initial value) or fatal 
error otherwise."

This does not appear to be true when the same-named properties have array values. 
See the test script for a quick example. It seems that it behaves as the 
documentation describes only with scalar values.

This is either missing/erroneous documentation (i.e. the behavior is intended), or 
it is a bug (i.e. equal array values should not cause a fatal error).

Test script:
---------------
trait Foo {public $var = [];}
trait Bar {public $var = [];}
class Baz {use Foo, Bar;}

Expected result:
----------------
To behave as the documentation describes, i.e. no fatal errors occuring.

Actual result:
--------------
PHP Fatal error:  Foo and Bar define the same property ($var) in the composition 
of Baz. However, the definition differs and is considered incompatible.


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



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


Thread (1 message)

  • metamarkers at gmail dot com
  • Unknown Message
    • metamarkers at gmail dot com
« previous php.bugs (#181584) next »