PHP without dollar signs :)

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
ecstatic.coder
Forum Newbie
Posts: 4
Joined: Thu Jul 20, 2017 10:22 am

PHP without dollar signs :)

Post 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>
Last edited by ecstatic.coder on Wed Jul 26, 2017 10:27 am, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP without dollar signs :)

Post by requinix »

So basically it's not PHP.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP without dollar signs :)

Post 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!
(#10850)
ecstatic.coder
Forum Newbie
Posts: 4
Joined: Thu Jul 20, 2017 10:22 am

Re: PHP without dollar signs :)

Post 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 ;)
ecstatic.coder
Forum Newbie
Posts: 4
Joined: Thu Jul 20, 2017 10:22 am

Re: PHP without dollar signs :)

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP without dollar signs :)

Post 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!
(#10850)
ecstatic.coder
Forum Newbie
Posts: 4
Joined: Thu Jul 20, 2017 10:22 am

Re: PHP without dollar signs :)

Post 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.
Post Reply