ZF2-326: Zend\Code\Generator allows invalid class/method/property names

Issue Type: Improvement Created: 2012-05-29T15:02:30.000+0000 Last Updated: 2012-10-08T20:15:15.000+0000 Status: Closed Fix version(s): Reporter: Adam Lundrigan (adamlundrigan) Assignee: Ralph Schindler (ralph) Tags: - Zend\Code\Generator

Related issues: - ZF-7645



[ Cloned from ZF-7645 ]

Zend_CodeGenerator does not prevent invalid PHP class/method/property names. For example, it allows names with spaces, names beginning with numbers, and names containing non-alphanumeric characters. The Zend_CodeGenerator component should not create invalid should either filter the names into usable values or throw an exception. Preferrably it filters the names (and any other invalid code) into valid, usable values.

An excellent example is having spaces in class (or method, or property) names...a simple solution would be to setup an inflection filter on the class name to convert spaces to camelcase or underscore...and this could perhaps be configurable.

On names beginning with numbers, we could either remove the number automatically, or prepend the name with an underscore (less desired though...underscore indicates a protected method/property).

Non-alphanumeric characters could be easily stripped with an Alnum filter.

This does nothing to address actual code validation inside methods...such as correct syntax. This would ideally be validated as well, but that is probably a separate issue in itself. A Zend_Validate class would need to be written for PHP code, and then used inside Zend_CodeGenerator. Probably have to throw an exception on invalid code...could be difficult and unreliable to attempt to correct it (but who knows, maybe someone out there can pull it off). The class/method/property names would be pretty easy to auto correct, but it might turn out that the best solution is exceptions also.


Posted by Ralph Schindler (ralph) on 2012-10-08T20:15:15.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit:

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.