Introduction

PHP tips and tricks is a treasure trove of PHP pieces of code. It collects all those quick one-liners, unexpected behaviors, hidden features and strange things that are concealed in the dark corners of PHP.

This encyclopedia has several goals:

  • entertain, with special situations and unexpected but valid usage of the PHP syntax

  • provoke thoughts, by bringing edge cases into the light. They might be bugs, tolerated behaviors or simply collateral damages

  • challenge PHP users with their knowledge of the language

This encyclopedia is for the advanced PHP users. Do not go there without a solid experience of the language, and a good sense of humour.

Contributions

Contributions are welcomed, by submitting PR to the repository.

  • code images are made with carbon. They shall be in the ‘images’ folder and be in png format.

  • id is the name of the file, and by convention, the name of the image.

  • title is the name of the tip. It should be short.

  • description is the longer description of the code snippet.

  • Keep the code simple and short. It should also provide some display, even if it is an error.

  • Deprecation is the version where a deprecation message is emitted by PHP (if any)

  • phpVersion is the first version where the code is valid

  • related[] are other PHP tips and tricks that are close but different.

  • seeAlso[] is a list of links to complements that details this tips even more: PHP manual, blogs, video, applications, etc.

  • alternative is an array of other features that can do the same.

  • phpError list the PHP error messages displayed by PHP

  • keywords[] is a tag system.

  • author is your name. Leave blank for anonymous.

  • contact is a link to contact you, if you want. Mail, blog, website, mastodon handle, twitter, instagram… you choose.

Obvious or documented features of PHP will be reviewed before being accepted. Removed features might be sidelined to avoid doing archeology.

Check the skeleton.ini file, and fill its entries. You can be credited for it.