PHP Internals News: Episode 87: Deprecating Ticks
PHP Internals News: Episode 87: Deprecating Ticks
In this episode of "PHP Internals News" I chat with Nikita Popov (Twitter, GitHub, Website) about the "Deprecating Ticks" RFC.
The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode's MP3 file, and it's available on Spotify and iTunes. There is a dedicated website: https://phpinternals.news
Transcript
- Derick Rethans 0:14
-
Hi I'm Derick, welcome to PHP internals news, a podcast dedicated to explaining the latest developments in the PHP language. This is episode 87. Today I'm talking with Nikita Popov about a much smaller RFC this time: Deprecating Ticks. Nikita, would you please introduce yourself.
- Nikita Popov 0:34
-
Hi Derick, I'm Nikita, and I'm working on PHP core development on behalf of JetBrains.
- Derick Rethans 0:40
-
Let's jump straight into what this RFC is about, and that's the word ticks. What are ticks?
- Nikita Popov 0:46
-
Ticks are a declare directive,. You write declare ticks equals one at the top of your file, and then PHP we'll call a tick function after every statement execution. Or if you write ticks equals two, then as we'll call it the function after every two statement executions.
- Derick Rethans 1:05
-
Do you have to specify which function that calls?
- Nikita Popov 1:08
-
Of course, so there is also a register tick function and unregister tick function and that's how you specify the function that should be called rather the functions.
- Derick Rethans 1:17
-
How does this work, historically, because the RFC talks about the change being made in PHP seven?
- Nikita Popov 1:22
-
Technically ticks work by introducing an opcode after every statement that calls the tick function depending on current count. The difference that was introduced in PHP seven is to what the tick declaration applies. The way PHP language semantics are supposed to work, is that declare directives are always local. The same way that strict types, only applies to a single file, ticks should also only apply to a single file. Prior to PHP seven, it didn't work out way. So if you had declare ticks, somewhere in your file, it would just enable ticks from that point forward. If you included the different file or even if the autoloader was triggered and included a different file that one would also make use of ticks. That was fixed in PHP seven, so now it is actually file local, but that also means that the ticks functionality at that point behaviour became, like, not very useful. Because usually if you want to use tics you actually want them to apply it to your whole codebase. There are ways around that. I'm afraid to say that people have approached me after this RFC and told me that they actually do that. The way around that is to register a stream wrapper. It's possible in PHP to unregister the file stream wrapper and register your own one, and then it's possible to intercept all the file includes and rewrite the file contents to include the declare ticks at the top of the file. I do use that general mechanism for real things in other places, but apparently people actually use that to like instrument, a whole application with ticks, and essentially restore the behaviour we had in PHP 5.
- Derick Rethans 3:03
-
What was the intended use case for ticks to begin with?
- Nikita Popov 3:07
-
Well I'm not sure what was the intended use case, but at least it was the main use case, and that's signal handl
Truncated by Planet PHP, read more at the original (another 10264 bytes)