c4tom / db2php

Automatically exported from code.google.com/p/db2php
GNU General Public License v3.0
0 stars 0 forks source link

Ability to generate extended classes and modify return types #10

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by baskooij...@gmail.com on 18 Nov 2009 at 11:02

GoogleCodeExporter commented 9 years ago
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

Original comment by rc.poi...@gmail.com on 21 Nov 2009 at 7:15