# php_basic_facts

 The flashcards below were created by user starkisspk on FreezingBlue Flashcards. There is no integer division operator in PHP. 1/2 yields the float 0.5. The value can be casted to an integer to round it downwards, or the round() function provides finer control over rounding. Assuming 2 compliment when you negate a positive number, the result is the negative of that number plus 1 ex. \$b = ~6; // \$b will be equal to -7 \$b = ~0; // \$b will be equal to -1 Assuming 2's compliment when you negate a negative number, the result is the positive of that number subtract 1 \$b = ~ -4; // \$b will be equal to 3 \$b = ~ -1; // \$b will be equal to 0 1) \$a & \$b //and 2) \$a | \$b //or (inclusive or) 3) \$a ^ \$b //Xor (exclusive or) 4) ~ \$a //not \$a << \$b //shift left \$a >> \$b //shift right 1) Set bits that are set in both \$a and \$b are set. 2) Set bits that are set in either \$a or \$b are set. 3) Set bits that are set in \$a or \$b but not both are set. 4) Shift the bits of \$a \$b steps to the left (each step means "multiply by two") 5) Shift the bits of \$a \$b steps to the right (each step means "divide by two") When setting a cookie on a page that redirects, the cookie must be set after the call to header('Location: ....'); Such as: Associativity Operator right [ right ! ~ ++ — (int) (float) (string) (array) (object) @ left * / % left << >> non-associative < <= > >= non-associative == != === !== left & left ^ left | left && left || left ?: right = += -= *= /= .= %= &= |= ^= <<= >>= left and left xor left or left , ++ and -- need to operate directly on a variable The following will result in a parse error \$a = 4; print ++\$a++; // cant use 2 increment/decrement operators on same variable print (++\$a)++; // still illegal print ~++\$a; // legal print ~(++\$a); // legal print !++\$a; // legal Although = has a lower precedence than most other operators, PHP will still allow expressions similar to the following: if (!\$a = foo()), in which case the return value of foo() is put into \$a. The division operator ("/") returns a float value unless the two operands are integers (or strings that get converted to integers) and the numbers are evenly divisible, in which case an integer value will be returned. Operands of modulus are converted to integers (by stripping the decimal part) before processing. If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable \$php_errormsg. This variable will be overwritten on each error, so check early if you want to use it. The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function and include() calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth. so what does the @ operator do? It temporarily sets the error reporting level to 0 for that line. If that line triggers an error, the error handler will still be called, but it will be called with an error level of 0 @include("file.php"); This causes, the error reporting level to be set to zero also for the included file. So if there are some errors in the included file, they will be not displayed. PHP supports one execution operator: backticks (``). Note that these are not single-quotes! PHP will attempt to execute the contents of the backticks as a shell command; the output will be returned (i.e., it won't simply be dumped to output; it can be assigned to a variable). Use of the backtick operator is identical to shell_exec(). \$output";?> The backtick operator is disabled when safe mode is enabled or shell_exec() is disabled. instanceof is used to determine whether a PHP variable is an instantiated object of a certain class: instanceof can also be used to determine whether a variable is an instantiated object of a class that inherits from a parent class: Lastly, instanceof can also be used to determine whether a variable is an instantiated object of a class that implements an interface: Although instanceof is usually used with a literal classname, it can also be used with another object or a string variable: \$a = new MyClass; \$b = new MyClass; \$c = 'MyClass'; \$d = 'NotMyClass'; var_dump(\$a instanceof \$b); // \$b is an object of class MyClassvar_dump(\$a instanceof \$c); // \$c is a string 'MyClass'var_dump(\$a instanceof \$d); // \$d is a string 'NotMyClass'?> you cannot break an if else statement between } else { ex: incorrect: correct: Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error. Php in, a continue statement in a switch statement has the same effect has a break statement. However the continue statement only seem to affect the switch. for example 'continue 2' would only affect the switch and not any outer loop Continue; inside a switch statement acts similar to a break statement. If the switch is inside a loop you can use continue 2; It will break out of the switch statement and continue with the next iteration of the outer loop. the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file. If no parameter is supplied, then the parentheses must be omitted and NULL will be returned. Calling return() with parentheses but with no arguments will result in a parse error. If called from the global scope, then execution of the current script file is ended. If the current script file was include()ed or require()ed, then control is passed back to the calling file. Furthermore, if the current script file was include()ed, then the value given to return() will be returned as the value of the include() call. If return() is called from within the main script file, then script execution ends. If the current script file was named by the auto_prepend_file or auto_append_file configuration options in php.ini, then that script file's execution is ended. Note: You should never use parentheses around your return variable when returning by reference, as this will not work. You canonly return variables by reference, not the result of a statement. If you use return (\$a); then you're not returning a variable, but the result of the expression (\$a) (which is, of course, the value of \$a). Authorstarkisspk ID9590 Card Setphp_basic_facts DescriptionBasic PHP FACTS Updated2010-03-25T08:08:34Z Show Answers