Etiqueta: PHP

Constants on PHP

A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script (except for magic constants, which aren’t actually constants). A constant is case-sensitive by default. By convention, constant identifiers are always uppercase. The name of a constant follows the same rules as

Continuar leyendo...

Variables From External Sources

When a form is submitted to a PHP script, the information from that form is automatically made available to the script. There are many ways to access this information, for example: Example #1 A simple HTML form <form action=»foo.php» method=»post»> Name: <input type=»text» name=»username» /><br /> Email: <input type=»text» name=»email» /><br /> <input type=»submit» name=»submit»

Continuar leyendo...

Variable variables on PHP

Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically. A normal variable is set with a statement such as: <?php $a = ‘hello’; ?> A variable variable takes the value of a variable and treats that as the name of

Continuar leyendo...

Variable scope on PHP

The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope. This single scope spans included and required files as well. For example: <?php $a = 1; include ‘b.inc’; ?> Here the $a variable will be available within the included b.inc

Continuar leyendo...

Default values of uninitialized variables on PHP

<?php // Unset AND unreferenced (no use context) variable; outputs NULL var_dump($unset_var); // Boolean usage; outputs ‘false’ (See ternary operators for more on this syntax) echo($unset_bool ? «true\n» : «false\n»); // String usage; outputs ‘string(3) «abc»‘ $unset_str .= ‘abc’; var_dump($unset_str); // Integer usage; outputs ‘int(25)’ $unset_int += 25; // 0 + 25 => 25 var_dump($unset_int);

Continuar leyendo...

Variables in PHP

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression,

Continuar leyendo...

NULL, the special value on PHP

The special NULL value represents a variable with no value. NULL is the only possible value of type NULL. Note: The null type was introduced in PHP 4. A variable is considered to be null if: it has been assigned the constant NULL. it has not been set to any value yet. it has been

Continuar leyendo...

Object Initialization on PHP

To create a new object, use the new statement to instantiate a class: <?php class foo { function do_foo() { echo «Doing foo.»; } } $bar = new foo; $bar->do_foo(); ?> Converting to object If an object is converted to an object, it is not modified. If a value of any other type is converted

Continuar leyendo...

Arrays on PHP

An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be

Continuar leyendo...

Strings on PHP

A string is series of characters, therefore, a character is the same as a byte. That is, there are exactly 256 different characters possible. This also implies that PHP has no native support of Unicode. See utf8_encode() and utf8_decode() for some basic Unicode functionality. Note: It is no problem for a string to become very

Continuar leyendo...