Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get class attributes without making an instance

Tags:

oop

forms

php

Here's the thing: I'm trying to make an automatic form generator based on my Model classes.

I would like to know if I can do it in PHP without first instatiating the model class. Personally I'm thinking it may be hard for PHP is not strong-typed, but I want to check.

Can I get the attributes, its names and types(probably the hardest part) from a non-static class in PHP without instantiating it? (Maybe reflection?)

Would it be a better idea to get the names and types from the Database and then create the form?

like image 782
Tiago Duque Avatar asked Nov 26 '25 04:11

Tiago Duque


1 Answers

The best approach is to modelize your entities using "Schema Definition Language", XSD files
After that, generate both of your PHP classes and forms using your XSD models ( in Java there is JAXB, but a small reseach in internet will give you a JAXB's like :) )

This Technique will ensure that if you decide to update your models, PHP Classes and Forms will be automatically generated (like Maven in Java)

like image 132
Halayem Anis Avatar answered Nov 28 '25 19:11

Halayem Anis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!