Export to GitHub

db2php - issue #10

Ability to generate extended classes and modify return types


Posted on Nov 18, 2009 by Helpful Dog

You discourage modifying the generated classes, since if you have to generate them again the changes will be lost. However, if I create a class that extends a generated class I'd have to modify the return types of the generated class to the extended type for it to be of any use.

Say I generated a class of a products table, called PHP2DB_Products. Then I create a class specified as MyProducts extends PHP2DB_Products. The MyProducts class contains a method called CalculatePrice. The following code would fails, since the return type of the findById method is PHP2DB_Products.

$prod = MyProducts::findById($db, $eventersId); echo $prod->CalculatePrice();

Casting is not an option since that would mean I'd have to upcast, which is not safe.

It would be nice of the plug-in would generate both the entity classes from the database tables and extended classes that people can use to program their own logic. The entity classes could then return the extended types.

Comment #1

Posted on Nov 21, 2009 by Grumpy Horse

Hello ^^ I am very aware of that :( At the moment I work with composition instead of inheritance to overcome the problem. Unfortunately PHP(Training wheels without the bike) doesn't support late static binding before 5.3. I'd have to kill off all static methods and the new versions would be incompatible with the old ones :( Either that or require 5.3. Since I use this at work and our hoster doesn't support 5.3 yet ... :/ Let me ponder a while. Regards, Andreas

Status: New

Labels:
Type-Defect Priority-Medium