Page 1 of 1

PHP without dollar signs :)

Posted: Thu Jul 20, 2017 11:20 am
by ecstatic.coder
Hi,

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

Most of the PHP syntax has been kept unchanged, except for 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.
- etc...

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

I know that this tool has absolutely zero interest for those who like PHP's current syntax as it is, but unfortunately for me I wasn't one of them...

https://github.com/senselogic/PHOENIX

Code: Select all

function GetMessage(
    string first_name,
    string last_name
    )
{
    global
        hello;
    local
        message;
        
    message = hello .. " " .. first_name .. " " .. last_name .. " !";
    
    return message;
}

class HOBBIT
{
    attribute 
        FirstName = "",
        LastName = "",
        RingCount = 0;
        
    static attribute
        HobbitCount = 0;
        
    method constructor(
        string first_name,
        string last_name,
        int ring_count
        )
    {
        .FirstName = first_name;
        .LastName = last_name;
        .RingCount = ring_count;
        
        self::AddHobbit();
    }

    method destructor()
    {
        .RemoveRings( .RingCount );
        
        self::RemoveHobbit();
    }
}

<ul>
    <? foreach ( var dwarf_name; dwarf_name_array ) { ?>
        <li>
            <% dwarf_name %>
        </li>
    <? } ?>
</ul>

Re: PHP without dollar signs :)

Posted: Thu Jul 20, 2017 11:59 am
by requinix
So basically it's not PHP.

Re: PHP without dollar signs :)

Posted: Thu Jul 20, 2017 2:18 pm
by Christopher
If these kind of syntax issues are that important to you then a preprocessor is the way to go.
ecstatic.coder wrote:I know that this tool has absolutely zero interest for those who like PHP's current syntax as it is, but unfortunately for me I wasn't one of them...
I think you misunderstand the people you call "those". Most people, myself included, switch between programming languages all day long and just not bothered by the syntax details of those languages. As long as I have programmed, there has always been a very small group of people, like you, who are very dogmatic about syntax. More power to you!

Re: PHP without dollar signs :)

Posted: Thu Jul 20, 2017 2:53 pm
by ecstatic.coder
requinix wrote:So basically it's not PHP.
Let say it's a "diet" version of PHP, with a bit less fat ;)

Re: PHP without dollar signs :)

Posted: Thu Jul 20, 2017 3:06 pm
by ecstatic.coder
Christopher wrote:As long as I have programmed, there has always been a very small group of people, like you, who are very dogmatic about syntax. More power to you!
Indeed, I admit it...

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

Hence the Javascript-like syntax, which seems to be a bit more easy on my brain...

But I know that many people don't have any readability problem with standard PHP code.

Re: PHP without dollar signs :)

Posted: Mon Jul 24, 2017 1:49 pm
by Christopher
Had you started with PHP (or Perl), you'd be struggling with Javascript. And honestly, of the strange languages in the world, Javascript is pretty weird. It is prototype based and there are a bunch of different ways to make objects. It you learned it first, you have a strange perspective on languages. But Javascript is event driven, DOM traversing fun!

Re: PHP without dollar signs :)

Posted: Mon Jul 24, 2017 2:44 pm
by ecstatic.coder
Being able to add properties to a class instance (like in JS and PHP) is indeed a fantastic feature, and I regularly miss it when using strongly-typed languages.

I think that if I had learned JS after PHP, I probably would have still preferred the leaner JS syntax, but that doesn't mean I would prefer to use JS over PHP for web development.

I've already used Node.js in the past, and obvioulsy PHP is way easier to use, even compared to Go, Dart, etc.

Rename index.html to index.php, add a few lines of PHP code inside dedicated tags, and you have your first web server up and running. Nothing can beat this approach in ease of use.