Function responses

There is a question going around about whether a PHP function should return a response. Is a function (or method), that does something and doesn't return anything any good? And I personally think - no its not good. A function should ALWAYS return something. Even if its true or false, $this or mysql_insert_id(). The main reason being that, if a function simply executes and does its thing, without returning anything, there is no way to verify if that function has executed successfully. If a PHP function call returns null once completed, but also returns null if there was an error of some sort, how does the developer know if it ran ok. Simply returning true, so you can verify if it ran as intended, or even throwing an exception is some form of return value, so if there is an issue this should be picked up by the developer and they can rely on their code working as intended.

Comments

Popular posts from this blog

Navigating the Jungle of Web Traffic: A Technical Team Lead's Guide to "I'm a Celebrity, Get Me Out of Here"

TCP Handshake over IPv6

The Vital Importance of Secure Wi-Fi Networks