---
title: "PHPtip tweets"
url: https://www.exakat.io/phptip-tweets/
date: 2022-09-19
modified: 2022-09-19
lang: en
author: "dams"
description: "PHP tips A pot-pourri of 8 PHP tips that were published with @exakat account. strict_types exceptions strict_types do not apply to #PHP operators, only on to typed structures. Here, concatenation..."
word_count: 267
---

# PHPtip tweets

# PHP tips

A pot-pourri of 8 PHP tips that were published with [@exakat](https://twitter.com/exakat) account.

---

## strict_types exceptions

strict_types do not apply to #PHP operators, only on to typed structures.

Here, concatenation and interpolation all call __toString(), but not foo().

As you can see, print() and echo() are safe too, while implode() is not.

![](https://www.exakat.io/phptip/phptip-1.png)
[Tweet](https://twitter.com/exakat/status/1571452922042650624)

---

## __invoke() and properties and methods

What does this tricky #PHP code displays?
![](https://www.exakat.io/phptip/phptip-2.png)
[Tweet](https://twitter.com/exakat/status/1569711228301496320)

---

## Method syntax and __invoke()

There are some other cases around instanceof, which are surprising upon first read.

We can use a string in a variable, but not a direct string, a constant nor a ::class.
![](https://www.exakat.io/phptip/phptip-3.png)
[Tweet](https://twitter.com/exakat/status/1569598507329232896)

---

## object is not a type

Such situations always make me smile, yet I am certain several of us will loose time on such a mistake.
![](https://www.exakat.io/phptip/phptip-4.png)
[Tweet](https://twitter.com/exakat/status/1568871734962720770)

---

## PHP keywords and namespaces

I was today's old when I realized that #PHP keyword are allowed in namespaces name since #PHP 8.0.

This goes to PHP 8.0 Compatibility ruleset.
![](https://www.exakat.io/phptip/phptip-5.png)
[Tweet](https://twitter.com/exakat/status/1567402995800805378)

---

## PHP silent optimisation

PHP optimisation in action : undefined variables are only reported when they are used.

first is omitted : no operation
second is skipped : no need to execute 2nd term
third is reporting a warning.

![](https://www.exakat.io/phptip/phptip-6.png)
[Tweet](https://twitter.com/exakat/status/1563547525688147968)

---

## PHP recycles

TIL PHP recycles the previously created stdClass objects. The following code returns Object #1, until it is stored in $b.

TIL (2) : PHP's stdClass's constructor omits all its arguments.

![](https://www.exakat.io/phptip/phptip-7.png)
[Tweet](https://twitter.com/exakat/status/1557621083615813632)

---

## When integer overflows

Mathematics have the 'Ramanujan Summation', where the sum of all integers is -1/12.

#PHP has the integer overflow. Stay away from the PHP_INT_MAX limits. Valid with (int) or intval() with recent #PHP versions.

![](https://www.exakat.io/phptip/phptip-8.png)
[Tweet](https://twitter.com/exakat/status/1552896398152048640)

---