09.22.07

Looseness of PHP Variables

Posted in PHP at 11:18 am by admin

One of the things that programmers detest with a passion about scripting is the fact that a lot of scripting languages require absolute rigidity when it comes to everything that’s done in a language.  This means that unless you are very confident of yourself, simply coding in something like notepad is not going to be a good idea for the simple reason that if you miss a period or other punctuation mark, you are going to have to manually search through everything in order to find it.

However, PHP is a bit different in that sense.  While there is a very clear syntax when it comes to the basic PHP commands, at the same time what you are going to find is that PHP is a loosely typed language.  This means that there are a lot of things that you can do that infer something that the PHP script will execute for you.  This might seem like bit of a foreign concept, so we will illustrate it further through the use of variables.

Take the following piece of example code:

<?php
$text = “PHP Rocks”;
$number = 1;
?>

This illustrates the basic $variablename = variablevalue; syntax that is used when declaring variables, but at the same time also illustrates that text or number strings need to be enclosed within quotation marks whilst non-string values do not.  These are all rigid aspects of the PHP language, but if you are familiar with other forms of programming you might have already noticed an important difference between PHP and many other programming forms.

In completely rigid programming languages, you need to specify both the name of the variable and the type of the variable before you can use it later on.  Examples of such languages include the C group of languages as well as older languages like Turbo Pascal.  In PHP however, you only need to signify the value and the script will automatically infer the appropriate type for you.  This is one of the things that make PHP a loosely typed language.

There are of course other things that make PHP a loosely typed language, but they are similar examples to what has been illustrated over the course of this article.  The PHP variables are useful in executing other parts of scripts and because of the fact that you don’t need to signify both the name and the type of the variable beforehand, you can save some space in your programming software.

Scriptycan is a great software repository featuring both free and commercial PHP scripts and applications for developers and programmers.

Leave a Comment

You must be logged in to post a comment.