It doesn’t work correctly in the newest version of GD (3.4.72) (The ball doesn’t collide with the left border, just flies away in this direction) but works fine in the previous version of GD.
The diff tool showed that both Example files are identical.