ID:               34592
 Updated by:       [EMAIL PROTECTED]
 Reported By:      david at nap dot edu
-Status:           Open
+Status:           Wont fix
 Bug Type:         Feature/Change Request
 Operating System: Redhat Linux / Fedora Core 3
 PHP Version:      5.0.5
 New Comment:

>however this has the disadvantage that they must
>remember to make the call to the superclass __construct 
>before doing anything else

Document it. It'll solve the problem.

I don't think that this deprecated feature will be supported even more
in the future.


Previous Comments:
------------------------------------------------------------------------

[2005-09-22 00:05:57] david at nap dot edu

> Why not to override __construct() instead?

  I could specify that users of my system must write constructors that
override __construct, however this has the disadvantage that they must
remember to make the call to the superclass __construct before doing
anything else (for example, assignments to class fields from a
constructor is common, and these need to be caught and mark object as
dirty).  I could also do something like specify that constructors in
domain objects have an underscore prepended to the name, such as
"function _MyClass() { ... }".  In this case if the underscore is
forgotten, errors will ensue much later due to __construct not being
called.  

Both of these seem less appealing than having users just write a ctor
in the way they are used to (named as class), and having it work. 

In general, I feel there should be a way to hook object creation for
non-end-user purposes (tracing, profiling, etc, as well) that is not
disabled by the presence of a constructor written by the user who is
not aware of the workings of the (persistence, tracing, profiling, etc)
mechanism.

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

[2005-09-21 23:53:08] [EMAIL PROTECTED]

>However, I'd prefer to allow users to implement 
>constructor methods named as the class;
Why not to override __construct() instead?


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

[2005-09-21 23:46:30] david at nap dot edu

Description:
------------
I'd like a configuration option that would disable backward-compatible
lookups of class constructor names (ie. methods named the same as the
class).

I'm attempting to implement a Hibernate-like persistence layer for php
objects.  To facilitate this, several things happen at object creation
time, currently using the 'magic method' __construct in a persistent
superclass.  However, I'd prefer to allow users to implement
constructor methods named as the class; in this scenario my
__construct() method would run and then use reflection to invoke the
user constructor.  However, this is not possible as the presence of the
class-named method currently prevents __construct  from being called.  

So, it would be useful to me to be able to switch off this behavior. 
If there is interest in this but no time I'd be happy to provide a
patch.

Reproduce code:
---------------
   class A {
     function __construct() {
       echo "A ctor\n";
     }
   }

   class B extends A {
     function B() {
       echo "B ctor\n";
     }
   }

   $foo = new B();



Expected result:
----------------
I'd like a php.ini option that would cause the result to be 

   A ctor

or even

   A ctor
   B ctor

if that is somehow more desirable.

Actual result:
--------------
Currently, the result is 

   B ctor



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


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

Reply via email to