Intro to PHP 2 Flashcards
Name two types of numeric variables
floating point and integer
How do you create an array>
$arraymine = array(‘Mii’);
PHP is a loosely typed language; what does this mean for variables?
variables do not have to be declared before they
are used
PHP always converts variables to the type required
by their context when they are accessed.
What are the key elements of strongly typed languages?
Static type checking
• Generate an error or refuse to compile
• No possibility of an unchecked runtime type error
In favor of type safety
– Smalltalk, Perl, JavaScript, Ruby, Python,
Describe a weakly typed language
Dynamic type-checking
Implicit type conversions
E.g. both C++ and C# allow programs to define operators to
convert a value from one type to another in a meaningful
way.
What are magic constants?
There are dozens already available without being defined, some of these are magic constants. They are:
_LINE_ _FILE_ _DIR_ _FUNCTION_ _CLASS_ _METHOD_ _NAMESPACE_
What is the difference between echo and print?
print is a function that takes in a variable (returns something)
echo is a php language construct(does not return anything)
What is the difference between a local and global variable?
Local variables cannot be used outside without a function. they are not to be used for long term variables, but usuall just to be used within a function.
Global variables need to use the keyword global
What is a superglobal?
They are predefined by the php environment and are accessible from anywhere
Name three super globals
$GLOBALS $_GET $_POST $_FILES $_SESSION $_REQUEST
How would you avoid attackers using superglobals against you?
Sanitize them with the htmlentities PHP function
What is the difference between include and require?
Include will attempt to use the file. Require will attempt to use the file, and if it cannot be used, it will not continue with the program. It will stop