News for hackers. Stuff that matters.
Re:Modern PHP Cheat Sheet by superasn on Thursday November 25, 2021 @06:19AM (#29340351)
I really wish Php added support for Perl's qq and q operators sometime too (1)

It would really make writing scripts a lot easier and cleaner.

(1) https://stackoverflow.com/a/41334570/1031454

Re:Modern PHP Cheat Sheet by iforgotpassword on Thursday November 25, 2021 @06:24AM (#29340380)
I personally think it looks broken and wrong. For short strings I don't see the point and for multiline strings, use a heredoc.
Re:Modern PHP Cheat Sheet by vessel on Thursday November 25, 2021 @07:26AM (#29340748)
The reason I never use Heredoc is because you need to abandon your indentation, otherwise your tabs/spaces get included in the string. Is there a way around that?
Re:Modern PHP Cheat Sheet by mrcarrot on Thursday November 25, 2021 @07:32AM (#29340789)
Not since PHP 7.3![1] If you indent the closing identifier, then the corresponding indentation will be removed from the content of the heredoc string.

[1]: https://www.php.net/manual/en/language.types.string.php#lang...

Re:Modern PHP Cheat Sheet by TrispusAttucks on Thursday November 25, 2021 @07:34AM (#29340804)
I thought they fixed this with [1] Flexible Heredoc in 2017 with PHP 7.3

[1] https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes

Re:Modern PHP Cheat Sheet by syberspace on Thursday November 25, 2021 @07:16AM (#29340687)
I've gotten into the habit of generally using single quoted strings (with 'around them') which alleviates most problems with escaping double quotes. And for the odd string that needs to have a single quote inside I switch back to double quoting.

This approach also has the added bonus of stopping PHP from accidentally evaluating something inside the strings.