Extended ASCII characters are valid php variable names

A curiosity…

I was looking on the php.net website for what qualifies as a valid PHP class name, which they qualify as:

A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. came across this statement

Source PHP reference page

But they then add the following:

As a regular expression, it would be expressed thus: [a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff]*


(\x7f-\xff is the extended ascii character set)

Couldn’t believe it. Tried it, turns out it’s true. This is totally valid:

class € {
    function __toString()
        return "I'm a euro!";

echo new €;

Turns out it’s also valid for functions and variables (with $ prefix obviously). Let’s up the crazy:

class • {
    function °() {
        echo "•_°";

$• = new •;


Yep, that totally works.


Hmmmm, if I ever need to make some PHP less readable, I know where to go.

Leave a Reply

Your email address will not be published. Required fields are marked *