Validate namespace definition

Asked

Viewed 94 times

1

PHP variables, if necessary, can be validated with the following Regular Expression:

[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

But what about the namespaces?

I have a certain string, coming from a form, which will serve as the name of a directory which will contain classes with namespaces.

Take as an example that Application fully functional which I use as playground testing, whose part of the directory structure, from the root directory, is:

|-\application
| \-\application\dovahkiin
|   |-\application\dovahkiin\application.php

The expression to be validated in this case would be the word dovahkiin.

And how I want to keep the process of self-loading simple, that is, just replacing the T_NS_SEPARATOR () by the DIRECTORY_SEPARATOR of the operating system and finally concatenating the file extension (thus), I need this string to be valid as part of a namespace.

I already know that non-alpha-numeric characters, such as dots and spaces, are invalid, but I’m not sure if the same Regular Expression used for variables would be valid for namespaces as well.

  • I could not understand your question, could provide data of namespaces that you consider valid? [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]. \x7f, by the table acsii is the delete, Still, you’re going up to the \xff that is, allowing these characters : ƒ,«,╣. If you’re talking about validating the variable’s scrotum and not its content, it would be this? ^(\$?[a-zA-Z_]\w*)$

  • The main reason for wanting to validate a namespace is precisely because it may be unknown. When me define my namespaces, I strictly use letters, but for validation, it may be that other characters are also valid. When it came to that Regular Expression, I didn’t create it. I just copied it of the manual

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.