Skip to content

Instantly share code, notes, and snippets.

@manuelpichler
Created November 29, 2011 16:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelpichler/1405317 to your computer and use it in GitHub Desktop.
Save manuelpichler/1405317 to your computer and use it in GitHub Desktop.
PHP is such an ugly language
<?php
class MyClass
{
static function myMethod(
$x = <<<'FOO'
Hello
FOO
, $y = <<<'BAR'
PHP_Depend
BAR
) {
echo $x, $y;
}
}
@edorian
Copy link

edorian commented Nov 29, 2011

+1 :)

@manuelpichler
Copy link
Author

You must always be aware on which line your comma, closing parenthesis etc. is! This sucks!!!11oneleven

@asgrim
Copy link

asgrim commented Nov 29, 2011

Umm, why not just do:

<?php
class MyClass
{
    static function myMethod($x = 'Hello', $y = ' PHP_Depend') {
        echo $x, $y;
    }
}

@manuelpichler
Copy link
Author

@asgrim

because it works :] But, to be serious. I would always do it similar to your example, but the intention of this gist was to show how ugly PHP is sometimes. And I am totally sad that it is so ...

@asgrim
Copy link

asgrim commented Nov 29, 2011

@manuelpichler

I see! To be fair to PHP, I think any language could be made to look ugly, I think it's just much easier to make ugly code using PHP over any other language. But yes, you're right, that is some awfully ugly code right there.

@manuelpichler
Copy link
Author

@asgrim

this wasn't a home brewed example, to promote PHP_Depenend. I have found it in project where PHP_Depend's parser failed to parse the source coce.

@edorian
Copy link

edorian commented Nov 29, 2011

"A project" as in "in production" ? Very nice, always good to see what php can do if you hit it hard enough. Thanks for sharing

@manuelpichler
Copy link
Author

@edorian

"A project" as in "in production"!!!11

@gsherwood
Copy link

:) I have the same problem with PHP_CodeSniffer. Seems we are both privileged enough to get a chance to look at some incredibly messy code via bug reports.

@manuelpichler
Copy link
Author

@gsherwood Yes same applies for PHP_Depend and PHPMD bug reports :-] Maybe we should create a shared repository for our projects, where we collect all those ugly code fragments for our test suites!?

By the way, have you already looked at the PHP-Parser project[1]?

[1] https://github.com/nikic/PHP-Parser

@johannes
Copy link

At least one place where the language is consistent, no special rules on constant expressions in different places.

@manuelpichler
Copy link
Author

@johannes

Maybe this is one of the consistent features in PHP, but in my totally personal opinion this language construct was/is already for simple variables an unreadable crap, and so I was more or less shocked, when I realized that you can use here-/nowdoc nearly everywhere.

@johannes
Copy link

johannes commented Dec 1, 2011

It is an constant expression, why create an extra rule limiting this? This brings complexity to the parser etc. If people want to do bad things they always can, inventing arbitrary artificial unneeded limitations is bad and makes the language more complex. We have cases which look like arbitrary limitations in the syntax, and that's always a pain ...

@manuelpichler
Copy link
Author

I do not critizes this syntax consistency at all, but I hate/dislike the now- and heredoc syntax in general from the first day and so this usage looks so ugly for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment