Last week we used Weak Maps to solve one edge case. Today, we simplify the most common and annoying edge case: That of nothingness.
Let’s be honest, null values suck. They’ve been called the billion dollar mistake, but programmers in most languages still have to deal with it. (Except for those working in Rust.) They especially suck when you have a variable that could be an object or null. If it’s an object, presumably you know it’s type and what it can do; if it’s null, you can’t do much of anything with it.
Tag: SourceGuardian Decoder
Picking the Right PHP for IBM i
It can be hard to decide on the right PHP for IBM i. This blog looks at factors every team should be consider before making their choice.
Step-debugging linked composer dependencies with PhpStorm – Rob Allen
One project I’m working on has multiple separate parts in different git repositories that are brought into the main project using linked composer directories. I needed to get step debugging working in PhpStorm and this is the approach I took.
Directory layout
My project is laid out on disk like this:
. ├── main-app/ │ ├── public/ │ ├── src/ │ ├── tests/ │ ├── vendor/ │ └── composer.json └── plugin-one/ ├── src/ └── tests/
As you can see I have main-app and plugin-one which are the two sets of source code that I need to work on.
Linked directories in composer
We need to set up ./plugin-one/ as a composer dependency of ./main-app/ such that it appears under ./main-app/vendor/client/plugin-one/, but set-up so that we can edit the original files and have main-app pick up the changes.
This is done by setting up a repository in our composer.json that points to the relevant path using a symlink. These are know as Path repositories and look like this in ./main-app/composer.json:
"repositories": [ { "type": "path", "url": "../plugin-one" "options": { "symlink": true } }, ]
I can then set my require like this:
"require": { "client/plugin-one": "@dev", },
The net result is that ./main-app/vendor/client/plugin-one is a symlink to ./plugin-one
Setting up PhpStorm
We create a PhpStorm project for ./main-app and then add plug-one to it as a “content root”:
- Go to Preferences -> Directories
- Click “+ Add Content Root” add add {full path}/plugin-one
- Click “Apply” and then “OK” to close the Preferences dialog
We now have the same source code in the project twice (once in ./plugin-one and once in ./main-app/vendor/client/plugin-one), so we need to excluded the vendor directory:
- In the Project tree view, find the main-app/vendor/client/plugin-one folder and select it
- Right click -> Mark Directory As -> Excluded
The folder will now be coloured orange, so we know it’s excluded.
Set-up for debugging
PhpStorm now knows about our source code, so next we need to map it to the server. I’m using Docker for this project, but it’s the for any remote-like project.
- Go to Preferences -> Languages & Frameworks -> PHP -> Servers
- Add a new entry:
- Name: {dev-hostname-for-main-app}
- Host: {dev-hostname-for-main-app}
- Port: 8888 (or whatever)
- Debugger: Xdebug (of course!)
- [✓] Use path mappings
- In the File/Directory list set up these mappings:
- {full path on local disk}/main-app => /var/www/html/main-app
- {full path on local disk}/plugin-one => /var/www/html/plugin-one
The key bit for this article is that path mapping section. The "/var/www/html" is whatever the correct path is on your Docker/Vagrant/whatever host.
Finally, click the menu item Run -> Start Listening for PHP Debug Connections. Note that if this is already selected, then the menu item does not exist and the menu item Stop Listening for PHP Debug Connections is in its place.
Start debugging
You can now set breakpoints in plugin-one/src/whatever.php and PhpStorm will stop on them.
If you are debugging a website using a browser then get the relevant Xdebug extension for Chrome or Firefox.
If it’s an API, then you’ll need to set a cookie to enable Xdebug for the request:
curl --cookie 'XDEBUG_SESSION=PHPSTORM; path=/' "http://{dev-hostname-for-main-app}:8888/foo/bar"
Translate to your API client of choice!
Fin
This worked for me, hopefully it’ll work for you too if you have a similar situation!
Interview with Dave Stokes – Voices of the ElePHPant
Interview with Miriam Schwab and Zeev Suraski – Voices of the ElePHPant
Show Notes
Audio
This episode is sponsored by
RingCentral Developers
The post Interview with Miriam Schwab and Zeev Suraski appeared first on Voices of the ElePHPant.
Xdebug Update: September 2020 – Derick Rethans
Xdebug Update: September 2020
Another monthly update where I explain what happened with Xdebug development in this past month. These will be published on the first Tuesday after the 5th of each month.
Patreon and GitHub supporters will get it earlier, on the first of each month.
I am currently looking for more funding.
You can become a patron or support me through GitHub Sponsors I am currently 59% towards my $1,000 per month goal.
If you are leading a team or company, then it is also possible to support Xdebug through a subscription.
In September, I worked on Xdebug for about 60 hours, with funding being around 70 hours. I worked mostly on the following things:
Xdebug 3
This month I mostly focussed on getting Xdebug 3 in shape for a first beta release, with all the new configuration names in place. There are now only a few tasks before I can release Xdebug 3.0.0beta1. I plan to release this around PHP 8.0RC2.
The main changes that I made was to rename the following four configuration settings, mostly to get “rid” of the remote naming:
-
xdebug.remote_host
→xdebug.client_host
-
xdebug.remote_port
→xdebug.client_port
-
xdebug.remote_connect_back
→xdebug.discover_client_host
-
xdebug.remote_addr_header
→xdebug.client_discovery_header
I hope that these new names are easier to explain, and of course the upgrade guide explains the changes too.
PHP 8
Although RC1 of PHP 8 is released today, there are still numerous items still in flux. In September there were various changes due to PHP 8’s new named parameters. This mostly has an effect on Xdebug’s tests, where these names are exposed as part of tracing or debugging tests. Because there are still changes, I am delaying Xdebug 3.0.0beta1 until PHP 8.0RC2.
Other API changes also meant that I had to make changes in Xdebug. Most notably related to code coverage, where PHP 8 will emit fewer Op codes and now (finally!) creates ASSIGN operations on the correct line (which makes Xdebug’s breakpoint resolving feature less necessary).
Releases
There were two Xdebug releases in September. 2.9.7 changes the step debugger to set up TCP Keepalive probes. This results in better time-out management in case network connections between Xdebug and an IDE drops.
Unfortunately this patch caused compilation issues on FreeBSD where some OS specific flags are different (but the same as OSX, which Xdebug did handle correctly). A fix for this, as well as a fix for path/branch coverage with foreach loops resulted in the 2.9.8 release. I expect to create one more release related to the TCP Keepalive addition as the current release still does not compile for AIX.
Beyond this, I do not expect any more release of the Xdebug 2.9 series unless security or crash bugs are present.
Xdebug Cloud
Beyond fixing an off-by-one error in host name generation, I did not write any code for Xdebug Cloud. However, work is ongoing on a web site, and JetBrains is also working on supporting Xdebug Cloud in PhpStorm. Reports state that a prototype is now working. With one IDE soon to support Xdebug Cloud I am also sharing the protocol changes with other IDE/debug client authors before I make it part of the DBGp specification.
Truncated by Planet PHP, read more at the original (another 1282 bytes)
Combining Swoole and Mezzio for Async Programming in PHP
In this blog, we show how to combine Swoole and Mezzio for speedy async programming in PHP applications.
PHP 8.0.0 Release Candidate 1 available for testing – PHP: Hypertext Preprocessor
The PHP team is pleased to announce the eighth testing release of PHP 8.0.0, Release Candidate 1. At this time, we’re not planning to adjust the GA date, however this may change during the course of the RC cycle. The updated release schedule can, as always, be found on the PHP Wiki page about the PHP 8.0. For source downloads of PHP 8.0.0 Release Candidate 1 please visit the download page.Please carefully test this version and report any issues found in the bug reporting system.Please DO NOT use this version in production, it is an early test version. For more information on the new features and other changes, you can read the NEWS file, or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive. The next release will be the Release Candidate 2, planned for Oct 15 2020.The signatures for the release can be found in the manifest or on the QA site.Thank you for helping us make PHP better.
PHP 8.0 feature focus: Weak maps – platform.sh
In our last episode, we discussed PHP 8’s new match() expression. Today we look at an edge case feature that will save your edge case.
PHP 7.4 introduced the concept of Weak References, which allow an object to be referenced without incrementing its reference counter. That’s a bit obscure and in practice not all that useful in most cases. What we were really waiting for is Weak Maps, which have landed in PHP 8.