Weird Operators in PHP

https://news.ycombinator.com/rss Hits: 1
Summary

Weird operators in PHP Weird operators in PHP If you read the PHP documentation, you will learn about a ton of operators. If you haven’t learnt about PHP operators, go do that first, we’ll wait for you. Operators are usually made up with strange symbols, like !, -, =>, <=>, ^ or ~. Really, some are plain readable like and, while some are merely an missed attempt at being readable, and actually hide a double personnality, like xor. You probably think you know PHP’s documentation in and out, but there is always more to learn. So I dove deep into the core of PHP code, and looked some special PHP operators that are lesser known, but very useful in your daily coding. Here are 10 PHP operators you have to know in 2018! b’ operator Simply add a b before any string, and it will do nothing. This neat trick works with b and B and nothing else. It is here to remind us of the fate of PHP 6, since b looks like a 6. $string = b'content'; []= operator The short array append operator. It works just as you expect, by pushing the element on the right side to the array on the left. $array []= 'element'; Indeed, it is a lot more elegant than $array[] = 'element';. Some benchmarks tends to show it is a lot faster while other benchmarks show it is a lot slower. As usual, check if it applies to you before betting all your performances on such a trick. Sadly, there is not a word about this great tool in the manual. On the left object operator <- The left object operator was introduced in PHP to extend the ways of writing code : coders could write PHP right to left. Although the project was later discontinued for obscure reasons, the first operator to be supported was left in PHP. $c = $a>-B; For backward compatibility purposes, this code doesn’t reach the property B in the object $a, but simply compares $a to the opposite of B. – – > operator --> is also known as the ‘super object operator’, built on top of its remote cousin, ->. $object-->property --> works like ->, except when it doesn’t...

First seen: 2025-10-12 04:17

Last seen: 2025-10-12 04:17