Extension:PhpTags/Quick start guide

From Linux Web Expert

Usage

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.

This string can also contain "Strip marker", if were used the functions which returns it.

Illustrative examples are given here.

Short syntax

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; }}

Examples here

PhpTags Code

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.

PhpTags is an implementation of Magic expressions, rather than an alternative implementations of the PHP.
PhpTags does not contain any implementation constants, regular functions and objects, so their availability and results of the call depends on additional installed compatible extensions. A large number of native PHP functions implemented in Extension:PhpTags Functions. You just need to install it.
If several extensions implement one and the same constant, function, or object, for processing will be caused by extension that is the last in LocalSettings.php
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

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.

In PhpTags (just like in PHP) global variables must be declared global inside a page if they are going to be used in that page. A clear demonstration
just like in PHP a second way to access variables from the global scope is to use the special PhpTags-defined $GLOBALS array. Demonstration of global variables.

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

The parameters that will be passed in when the template is used available through the the special PhpTags-defined $argv array.

the first argument $argv[0] is always the page name on which there is an appeal to this variable. Example