Javascript function internals: arguments and this

27 11 / 2011

Javascript function internals: arguments and this

Inside a function exist 2 special objects: arguments and this. The arguments object, is an arraylike object that contains all of the arguments that were passed into the function. This has also has a property named callee, which is a pointer to the function that owns the arguments object. Consider the following factorial function: function factorial(num){ if (num <...

(Read More)

HTML5 main structure

26 10 / 2011

HTML5 main structure

The “head” The HTML5 doctype declaration it’s very short: So, it’s required by browsers that need the presence of a doctype to trigger standards mode, and this string does this reliably. Then we need to define the document’s character encoding (it is recommended UTF-8). This should be in the first 512 bytes of the...

(Read More)

Copying objects with __clone()

16 10 / 2011

Copying objects with __clone()

In PHP 4, copying an object was made by assigning from one variable to another, which was a source of many bugs. class MyClass {} $first = new MyClass(); $second = $first; // PHP 4: $second and $first are 2 distinct objects // PHP 5: $second and $first refer to one object Prior to PHP5, equivalence tests would tell you whether all fields were the same (==) or...

(Read More)

Interceptors and Delegation

15 10 / 2011

Interceptors and Delegation

PHP provides built-in interceptor methods, which can intercept messages sent to undefined methods and properties (a kind of overloading). The interceptor methods: Method Description __get( $property ) Invoked when an undefined property is accessed __set( $property, $value ) Invoked when a value is assigned to an undefined property __isset( $property...

(Read More)

Handling Errors in PHP

09 10 / 2011

Handling Errors in PHP

There are many situations when error-handling code is necessary: files are misplaced, database servers are left uninitialized, URLs are changed, XML files are mangled, permissions are poorly set, disk quotas are exceeded and so on. Here is a simple class that stores, retrieves, and sets data in an XML configuration file: class Conf { private $file; private...

(Read More)

Late Static Bindings (the static keyword)

06 10 / 2011

Late Static Bindings (the static keyword)

A static method can be used as factory, a way of generating instances of the containing class. Write the following example: abstract class BaseObject{ public static function create(){ return new self(); } } class User extends BaseObject{} class Document extends BaseObject{} Document::create(); Running this code you get this: Fatal error: Cannot instantiate...

(Read More)

Save data to files

05 10 / 2011

Save data to files

This tutorial demonstrates how to save a text entered by the user to the device’s internal storage (a file). Using Eclipse, create an Android project and name it StorageFiles. In the main.xml file, add the following statements: Edit StorageFilesActivity.java file like bellow: package files.storage; import java.io.FileInputStream; import...

(Read More)