ZF-9603: Zend_CodeGenerator allows invalid class/method/property names

Description

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 code...it 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.

Comments

While this behavior is semantically wrong, to change this method to include validation and/or filtering would change the functionality. This should be considered a functionality request and should be pushed towards ZF2 if it's still an issue.

Cannot be fixed in ZFv1 due to backwards-compatibiltiy issues. I've cloned this issue into ZF2 issue tracker as ZF2-326 for resolution there.