Recent Notes
Displaying keyword search results 1 - 10
Created by Fang on November 12, 2011 21:03:03
Last update: November 12, 2011 21:03:03
Experts may disagree but I found it absolutely stunning that JSF EL does not provide an operator for string concatenation. The Java "+" operator is there for the take. Java, which is a strongly typed compiled language, overloads the "+" operator in such a way that any object can be concatenated with a string. But JSF EL, which definitely isn't as strongly typed as Java, restricts the "+" operator to numerical values only! Of course, experts may argue that the "+" operator overloading is a huge design flaw of the Java language. But even so, JSF EL is not the right place to fix it! In some cases, a concatenation operator isn't needed, for example:
<ui:repeat var="tab" value="#{tabs}"> <img ... But in case the concatenated...
Created by voodoo on August 30, 2011 12:30:59
Last update: August 30, 2011 12:32:33
Summarized from The C Book : There are essentially two types of object in C: the internal and external objects. Anything declared outside a function is external; anything inside one, including its formal parameters, is internal. Since no function can be defined inside another, functions are always external. All function declarations implicitly have the extern keyword stuck in front of them, whether or not you put it there. These two declaearions are equivalent:
void some_function(void); extern void some_func... The term linkage is used to describe the accessibility of objects from one file to another. There are three types of linkage: external , internal , and no linkage . Type of linkage Type of object Accessibility external external Across files, througout the program internal external Within...
Created by jinx on May 04, 2011 20:01:08
Last update: May 04, 2011 20:02:59
A static variable in PHP functions and methods keeps its value after the function/method scope is exited, just like static variables in C. A static variable in a class is a class variable, and is accessed by the class name. In the global scope, static has no special meaning.
test.php:
<?php
include("test.inc");
include("...
test.inc:
<?php
static $i = 0;
$i++;
echo __FILE__,...
Output:
E:\phpwork\test.inc included: 1
E:\phpwork\test...
Created by jinx on May 03, 2011 12:11:35
Last update: May 03, 2011 12:12:27
The PHP function is_resource returns TRUE if a variable is a resource.
This may come in handy when a function you are calling returns mixed type. For example mysql_query returns TRUE or FALSE for INSERT , UPDATE , DELETE etc., but returns resource or FALSE for SELECT , SHOW , or DESCRIBE .
<?php
$rows = array();
if ($res = mysql_quer...
Created by jinx on May 03, 2011 11:43:26
Last update: May 03, 2011 11:43:26
The PHP function strval returns the string value of a variable. It does the same thing as casting a variable to string, or automatic conversion where string is expected.
Conversion rules:
Type String Value
Boolean TRUE '1'
Boolean FALSE '' (empty string)
integer of float string representing the number
Array The string 'Array'
Object Result of __toString() if defined, error otherwise
Resource 'Resource id #n' , where n is a number assigned to the resource.
NULL '' (empty string)
Example:
<?php
set_error_handler(function($errno, $errst...
Results:
bool(true)
---------------------
strval: '1'...
Created by jinx on May 02, 2011 11:55:53
Last update: May 02, 2011 11:57:20
The PHP function intval returns the integer value of a variable. But there are some gotchas:
The string ' 0x10 ' may look like hex, but it's not recognized as hex by intval unless base 0 is entered as the second argument.
With floating point numbers, round-off errors may produce surprising results (actually, intval truncates, it doesn't round off).
The number base argument is effective only when the variable is a string.
Examples:
<?php
echo 19.99 * 100, "\n"; // 1999
echo i...
Created by jinx on April 29, 2011 15:26:44
Last update: April 29, 2011 15:27:53
The PHP function set_error_handle sets a user defined error handler function. The example below uses a global variable to alter the execution path after error occurs:
<?php
$continue = true;
set_error_ha...
Output:
[Error Handler]
errno: 2
errstr: Division by...
Created by jinx on April 29, 2011 15:03:10
Last update: April 29, 2011 15:04:02
The PHP function is_callable verifies that a variable can be invoked as a function.
Example:
<?php
define('F', 'f');
function...
Output:
var_dump: string(1) "f"
is_callable: 1
Calla...
Created by jinx on April 29, 2011 13:43:13
Last update: April 29, 2011 13:44:34
List of functions testing variable type:
Function Description
is_bool Finds out whether a variable is a boolean
is_double Alias of is_float()
is_float Finds whether the type of a variable is float
is_int Find whether the type of a variable is integer
is_integer Alias of is_int()
is_long Alias of is_int()
is_null Finds whether a variable is NULL
is_numeric Finds whether a variable is a number or a numeric string
is_object Finds whether a variable is an object
is_real Alias of is_float()
is_scalar Finds whether a variable is a scalar
is_string Find whether the type of a variable is string
Test code:
<?php
class A {
}
$a = ar...
Output:
var_dump: int(1)
-------------------------
i...
Created by jinx on April 28, 2011 20:52:45
Last update: April 29, 2011 13:27:31
This is normally a syntax error just before some variable. Try some of these:
Missing operator before a variable:
<?php
$a = 'ab';
echo('Missing conca...
Missing semicolon at end of line:
<?php
echo('Missing semicolon at end of lin...
Missing ( and ) in for loop:
<?php
foreach $a as $i {
echo "$i\n";
...
Missing keyword before class variable:
<?php
class A {
// should be var $a;
...