xp-framework/rfc — Issue #236: Extension methods
Author: thekid
Created: 2012-02-11 10:06:59+00:00
State: open
Labels: framework, language

Scope of Change
==
Extension methods will replace native function calls in XP language.

Rationale
==
When writing XP language code, every PHP function needs to be imported via `import native`. The reason for this is that native function usage makes code more difficult to port to different platforms (e.g., HipHop, or a future NodeJS platform, for example).

Functionality
==
To discover native function usage in an XP language project, one can use the *grep* utility:

```sh
$ grep -Hirn '^import native' src | cut -d ' ' -f 3 | sort | uniq -c | sort -rn
```

Exemplary analysis
--
For [the Dialog photoblog software](https://github.com/thekid/dialog), the top 10 functions used are:

`sprintf, unserialize, sscanf, serialize, substr, sizeof, strpos, is_file, file_get_contents` and `dirname`.

*Side note: Especially PHP's serialization mechanism has had multiple problems in the past - accessibility levels (public / private / protected in PHP 4 -> PHP 5) and namespaces vs. non-namespaces (PHP 5.2 -> PHP 5.3) and should thus be replaced by a completely separate functionality in the framework - see RFC #6!*

Looking at the next 10 most often used functions, we see:

`basename, array_keys, usort, strolower, str_replace, krsort, implode, preg_replace, create_function` and `max`.

Observation
--
The most commonly used PHP functions are string and array functions.

Security considerations
==

Speed impact
==

Dependencies
==

Related documents
==