我想基于MySQL数据库中字符串定义的类型在PHP中创建一个对象.数据库表包含以下列和示例数据:
id | type | propertyVal
----+------+-------------
1 | foo | lorum
2 | bar | ipsum
...使用PHP数据类型
class ParentClass {...}
class Foo extends ParentClass {private $id, $propertyVal; ...}
class Bar extends ParentClass {private $id, $propertyVal; ...}
//...(more classes)...
仅使用一个查询,我希望按id Select 一行,并创建一个类型为define the table的type column的对象,将所选行中的其他列分配给新创建的对象.
我当时在想:
mysql_fetch_object()
- 读取类型属性
- 创建类型由type属性定义的对象
但我们不知道如何基于字符串动态创建类型.这是怎么做到的?