Functions With or Without Return Primer Tutorial

Functions With or Without Return Primer Tutorial

Our mention of the WordPress function wp_title( ‘|’, true, ‘right’ ) in Search Engine Optimization Meta Description Primer Tutorial, with its dual mode (function) return or no return (for display only) modes of use, reminded us of the “easy” ways of PHP as a language. For …

  • PHP not to care about whether a function returns a value or not … is pretty flexible … and then to consider …
  • PHP not caring about the data type of incoming parameters (or arguments) to functions is truly amazing … but Javascript is similarly flexible, as can be Python and Perl below

We decided to put the first one to the test with other languages, and became amazed that the same type of functional writing as you find in WordPress PHP function wp_title is tolerated in all but Java out of …

  • Java
  • C++
  • C
  • PHP
  • Python
  • Perl
  • Javascript

… though C++ and C warned about “control may reach end of non-void function” during the gcc compilation we made. Java compiled with the error “missing return statement”.

Here is the simple programming source code we wrote to show this …

Java
Erroneous (“missing return statement”)

Okay, but a compromise to way wp_title works …
C++ (warning: “control may reach end of non-void function”)
C (warning: “control may reach end of non-void function”)
PHP
Python
Perl
Javascript


Live Run use of Javascript

For an explanation of PHP’s flexibility with return values, take a read of this interesting read.

If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *