PHP without dollar signs :)

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jul 20, 2017 12:25 pm

Thu Jul 20, 2017 12:45 pm


I've just released an open-source tool (Phoenix) which allows to program PHP code with a slightly different syntax.

Most of the PHP syntax has been kept unchanged, but there are a few "tweaks" :
- dollar signs and 'this' are now implicit (i.e. not needed);
- '..' is used to concatenate strings, and '.' to access class members;
- the foreach loop syntax is 'foreach ( value; array )';
- '<? ... ?>' blocks contain Phoenix statements;
- '<% ... %>' blocks contain expressions to echo;
- '<# ... #>' blocks contain escaped expressions to echo.

The main drawback is that you have to declare your local variables with a 'local' statement, and put your code in files with the '.phx' extension instead of '.php'.

I've implemented this tool because I've always had a hard time decoding PHP code, especially with all these dollar signs flourishing everywhere in the PHP expressions.

Of course, I know it's of no interest for those who don't have any readability problem with PHP's current syntax, but unfortunately for me, I wasn't one of them...

So I thought it was still worth mentioning that this tool exists, in the case I wouldn't be alone in this case.

Code: Select all

function GetMessage(
    string first_name,
    string last_name
    message = hello .. " " .. first_name .. " " .. last_name .. " !";
    return message;

class HOBBIT
        FirstName = "",
        LastName = "",
        RingCount = 0;
    static attribute
        HobbitCount = 0;
    function constructor(
        string first_name,
        string last_name,
        int ring_count
        .FirstName = first_name;
        .LastName = last_name;
        .RingCount = ring_count;

    function destructor()
        .RemoveRings( .RingCount );

    <? foreach ( dwarf_name; dwarf_name_array ) { ?>
            <% dwarf_name %>
    <? } ?>

New php-forum User
New php-forum User
Posts: 24
Joined: Sat Dec 02, 2017 3:12 pm

Sat Dec 02, 2017 5:12 pm

I have a hard time decoding code that doesn't clearly indicate what words are variables. I'm slightly colorblind so syntax highlighting doesn't help me much.

I can understand getting rid of $ but getting rid of "this"? How do tell the object's id property from a local temporary id variable within a method?

Post Reply