Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP Do's and Don'ts

Tyrsson

Active Coder
For those new to php. You might want to take a day or two and read this:

Here's a short list of do's and don'ts

  • Use composer, and its autoloader.
  • Use a good DBAL for database access.
  • Don't put your queries in the same files that contain your markup.
  • Don't mutate globals. Use psr-7/15.
  • Use a bootstrap file and keep your executables out of the document root of the web server.
  • Learn OO, its powerful.
  • If your version of php supports it, use declare(strict_types=1) and if it doesn't, upgrade your php version.
  • Do not reinvent the wheel. If there is a well maintained lib, use it.
  • Stay out of the global scope.
  • Build to the interface.
  • Did I mention learn OO?
  • Do NOT use eval.
  • Do not try to write your own cryptography functions/methods. There is a 99% chance it's a bad idea.
  • Even if you just have to use functions instead of classes and methods, please, for the love of everything good in the universe. Type your arguments and returns.
  • Depend on the abstraction not the concrete implementation.
  • Generally prefer composition over inheritance.
That's all for now.
 

Buy us a coffee!

Back
Top Bottom