Live data from Hacker News

Modern PHP Cheat Sheet

front-line-php.com

11–20 of 127 posts

Re: Modern PHP Cheat Sheet

#13
post #7

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

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.

Re: Modern PHP Cheat Sheet

#15
post #3

I like how PHP is evolving. I wouldn't say it's always a joy to use but it definitively improved a lot.

I really want to use PHP for one-off CGI scripts, (rsync files and done, deployed), but I really wish it had methods on primitive types. It hinders discoverability. It's annoying having to look up which function I need to use, and to find that there are many alternatives, most of which are deprecated.

PHP stdlib needs an overhaul, IMO.

Re: Modern PHP Cheat Sheet

#16
The comment on Numeric values is misleading:

> Use the _ operator to format numeric values:

> $price = 100_10;

> // $100 and 10 cents

Makes it sound like the underscore replaces the decimal, which it doesn't. The underscores are simply ignored by the PHP parser, so that 10_0.1 === 1_00.1.

You could afterwards use PHP to replace the `_` with a comma for display purposes, and I assume that is what they are trying to say.

Re: Modern PHP Cheat Sheet

#18
post #7

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

I personally think it looks broken and wrong. For short strings I don't see the point and for multiline strings, use a heredoc.

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

#19
post #18

Earlier quoted context omitted.

I personally think it looks broken and wrong. For short strings I don't see the point and for multiline strings, use a heredoc.

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?

[deleted]

Re: Modern PHP Cheat Sheet

#20
post #18

Earlier quoted context omitted.

I personally think it looks broken and wrong. For short strings I don't see the point and for multiline strings, use a heredoc.

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?

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

Post reply on HN