Extension:PhpTags/Quick start guide
Usage
[edit]There are two ways to use this extension on the wiki pages, and each of them has its own features.
The main way is to place the PHP code between the tags <phptag>
and </phptag>
.
<phptag>
$foo = 'hello world';
echo ucfirst( $foo . "!!!\n" );
</phptag>
In this case PhpTags returns "Strip marker" and the result is sent for processing to the MediaWiki Parser.
Another way is to use PhpTags as the parser function:
{{#phptag: $foo = 'hello world'; echo ucfirst( $foo . "!!!\n" ); }}
In this case PhpTags returns string that can be processed by other parser functions.
Illustrative examples are given here.
Short syntax
[edit]For ease of use it is possible to use the short syntax.
short syntax | equivalent | |
---|---|---|
functions | {{#phptag: function_name | argument_1 | $argument_N | ... }} | {{#phptag: echo function_name( argument_1, $argument_N, ...); }} |
{{#phptag: function_name | }} | {{#phptag: echo function_name(); }} | |
variables | {{#phptag: $variable_name }} | {{#phptag: echo $variable_name; }} |
PhpTags Code
[edit]PHP is easy to learn and popular programming language and PhpTags designed so to be as similar to native PHP. Thus any PHP code should work correctly in PhpTags.
Implemented | Awaiting the implementation | Not implemented | |
---|---|---|---|
Types | Booleans, Integers, Floating point numbers, Strings, Arrays, Objects, NULL | Callbacks | Resources |
Variables | Predefined Variables ( $GLOBALS, $argv, $argc ), Variable scope(limited to the page, static, global) | Predefined Variables ( $_GET, $_POST, $_FILES, $_REQUEST, $_SESSION, $_COOKIE ), Variable variables | |
Operators | Arithmetic Operators, Assignment Operators, Bitwise Operators, Comparison Operators, Incrementing/Decrementing Operators, Logical Operators, String Operators, Array Operators, Error Control Operators | Type Operators | Execution Operators |
Control Structures | if, else, elseif, while, do-while, for, foreach, break, continue, | Alternative syntax for control structures, switch, return, goto | declare, require, include, require_once, include_once |
Constants | Extension-defined constants, Extension-defined magic constants | ||
Functions | Extension-defined function | User-defined functions, Variable functions, Anonymous functions | |
Objects | Extension-defined objects | Object Cloning | Classes |
Exceptions | try, catch, finally | Extending Exceptions |
Variable scope
[edit]The scope of a variable is the context within which it is defined. For the most part all PhpTags variables only have a single scope. Any variable used inside a page is by default limited to the local page scope.
Another important feature of variable scoping is the static variable. A static variable exists only in a local page scope, but it does not lose its value when PhpTags execution leaves this scope.
Demonstration of static variables.
Template parameters
[edit]The parameters that will be passed in when the template is used available through the the special PhpTags-defined $argv
array.
$argv[0]
is always the page name on which there is an appeal to this variable.
Example