HSL operators

From Halon Security
(Redirected from HSL Operators)
Jump to: navigation, search

Operator are fed with one or more values (or expressions) which yields another value (so that the operator itself becomes an expression). Expressions can be combinations of operators, functions and variables.

Contents

Example

The code below will print "1" to the logging facility, or terminal.

$variable = (== 1);
echo 
$variable

In the example above;

List of Operator Types

Below are the available operator types described. Note that operators are always part of expressions. If no parentheses are used when combining multiple operators within a statement, the expression is automatically traversed from the left to the right. Therefore, the expression 2 + 2 + "test" will return "4test". The exception is multiplication, division and modulus, which has higher priority than plus and minus.

Assignment Operators

Assignments will put whatever is returned from the expression to the right and place in the variable to the left. An expression consisting of an assignment will return the value that was assigned. Example 1 sets $variable to "test". Example 2 demonstrates an assignment as an expression, which will print "2" to the terminal/log.

Syntax Example 1 Example 2
$variable = expression;
$variable "test"
echo ($number 2); 

The complete list of assignment/arithmetic operators are "=", "+=", "-=", "*=" and "/=".

Arithmetic Operators

These are math operators, functional if the expressions (or variables) on both sides of the operator are numbers. The available operators are; +, -, /, * and %, where % is the modulus operator. You may do an assignment in combination with a arithmetic operator using += and -=.

Syntax Example
expression + expression;
$number = (2) + 2

The complete list of assignment/arithmetic operators are "=", "+=", "-=", "*=" and "/=".

String (Text) Operators

Using the + operator on a string (array of characters; text) will concatenate, combine, the strings.

Syntax Example
$string + expression;
$string "test" 2

Array Operators

Addition Operator

Using the + operator on an array will add (push) the value of the expression after the last position of the array. In case of a assignment expression, there are alternative ways to add an entry to a array.

Syntax Example
$array + expression;
$array = array();
$array $array "new item"
$array[] = expression;
$array[] = "new item"
$array += expression;
$array = array();
$array += "new item"

If the expression is an array, all values will be added to the array, but associative indexes will be overwritten and non associative indexes will be appended. If the $array does not exist, and you're using one of the "$array[]" expression a new array will be created, but not in the other examples because these types of assignments are NOT array specific.

Subtraction Operator

Using the - operator on an array will remove the value of the expression from the array. Index will NOT be reordered, removing one value will create a gap in the non associative index. See Core/Variables for a "work around".

Syntax Example
$array - expression;
$array = array("hello","new item","world");
$array $array "new item"
$array -= expression;
$array = array("hello","new item","world");
$array -= "new item"
$array -= expression;
$array = array("hello","new","item","world");
$array -= array("new,"item"); ?>

If the expression is an array, all values will be added removed from the array, it will ignore the indexes in both arrays - only values will be matched.

Multiplication and Division Operator

Using the * and / operators on arrays are not valid expressions, and if done so a runtime error will be trigged.

Logic Operators

Logics are the boolean, or discrete, kind of math. Like arithmetic operators, it requires the variables or expressions to be of the correct kind in order to produce expected results. Logic operators treats all expressions or variables as either true or false. The expressions 0 and false are interpreted as false, while all others are true. The available operators are and, or and not. The inversion operator "not" can also be written as !.

Syntax Syntax Example
expression and expression;
not expression 
$isfalse = (and false); 

Comparison Operators

These operators compare the expressions on both sides of the operator, and the expression as a whole will return either true or false. The comparisons able to operate on all data types are; == (equal), != (not equal), <, <=, > and >=. The operator =~ is true if the expression to the left matches the regular expression to the right and !~ is tue if they don't match .

Syntax Syntax Syntax Example
expression == expression;
expression =~ regex
expression !~ regex
$notequal = (== "test"); 

Regular Expression

The regular expression operator (=~ and !~) matches a string using partial match. That means in does not require you to supply the complete filter in order to match a substring. If you want to explicit mark the beginning or end of a filter you should use ^ for beginning and $ for the end.

String Filter Result
dummy@example.org
^dummy@example.org$
matches
dummy@example.org
@example.org$
matches
dummy@example.org
^dummy@
matches
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox