php, php Smybolic, php AST

PHP is an interesting language because it is very similar JSX in many ways. I would like to create a table comparing php 5 to php 7 but it appears PHP5.6 is now around 7% market share but this says 23% market share. tutorialspoint PHP7. PHP7 is pretty straight forwardish. I want to create a simple library that is both valid JS and allows of pasting of HTML code. PHP7 library that lets you use the most common javascript functions. php has special functions for utf-8 support. Detecting PHP

There is no operator overloading in php., but you can sort of extend the functions by making a class with __invoke. Arrays and Srings can not be subclassed effectively because gettype with no technique will return the correct value. To deal with utf-8 in php you use the mbstring functions and mysql uses `utf8mb4` for character set. I need to break down the PHP functions and wordpress internal php functions.

function sr_length($a){return count($a);}
function s_indexOf($a){return strpos();}
function mb_str_split(str){print_r(mb_split("\s", "hello world") );}
function mb_strlen(str){str.length}
mb_strpos("test","t",int $offset = 0);
mb_strrchr(
    string $haystack,
    string $needle,
    bool $before_needle = false
 );
mb_strrichr(
    string $haystack,
    string $needle,
    bool $before_needle = false,
    ?string $encoding = null
);
echo mb_substr_count("This is a test", "is"); // prints out 2
mb_substr(
    string $string,
    int $start,
    ?int $length = null,
    ?string $encoding = null
);
mb_strstr(
    string $haystack,
    string $needle,
    bool $before_needle = false,
    ?string $encoding = null
);

$values = [65, 63, 0x20AC, 128024];
foreach ($values as $value) {
    var_dump(mb_chr($value, 'UTF-8'));
    var_dump(mb_chr($value, 'ISO-8859-1'));
}

mb_strtoupper
mb_strtlower

if (preg_match('/1999/', $s)) {
  echo "party!\n";
}
if (s.match(/1999/)) {
  console.log('party!');
}

$s = "do re mi mi mi";
$s = preg_replace('/mi/', "ma", $s);

s = 'do re mi mi mi';
s.replace(/mi/g, 'ma');

a.filter((x) => x > 1)	

array_filter([1, 2, 3],
  function ($x) {
    return $x>1;
  })

array_reduce([1, 2, 3],
  function($x,$y) {
    return $x + $y;
  }, 0)

a.reduce((m, o) => m + o, 0)	

Unlike preg_replace, mb_ereg_replace doesn't use separators
$data = preg_replace("/[^A-Za-z0-9\.\-]/","",$data);

https://stackoverflow.com/q/1319903
let a = [1, [2, [3, 4]]];
let a2 = _.flatten(a);

mb_check_encoding, mb_convert_encoding, mb_encode_mimeheader, mb_encode_numericentity, mb_encoding_aliases mb_internal_encoding mb_list_encodings mb_regex_encoding 

iconv_strlen mb_strlen 
https://stackoverflow.com/q/1082780

class X {
    private $non_static_member = 1;
    private static $static_member = 2;

    function __construct() {
        echo $this->non_static_member . ' '
           . self::$static_member;
    }
}
new X();

mb_convert_case Perform case folding on a string
mb_parse_str Parse GET/POST/COOKIE data and set global variable
mb_split Split multibyte string using regular expression
mb_strcut Get part of string
mb_strimwidth Get truncated string with specified width
mb_stripos Finds position of first occurrence of a string within another, case insensitive
mb_stristr Finds first occurrence of a string within another, case insensitive
mb_strlen Get string length
mb_strpos Find position of first occurrence of string in a string
mb_strrchr Finds the last occurrence of a character in a string within another
mb_strrichr Finds the last occurrence of a character in a string within another, case insensitive
mb_strripos Finds position of last occurrence of a string within another, case insensitive
mb_strrpos Find position of last occurrence of a string in a string
mb_strstr Finds first occurrence of a string within another
mb_strtolower Make a string lowercase
mb_strtoupper Make a string uppercase
mb_strwidth Return width of string
mb_substr_count Count the number of substring occurrences
mb_substr Get part of string



a`!doctype html>test`;  
  console.log("test");
  
a`

`;
// ./ directory of php.ini
php -c ./ -S localhost:80 index.php
echo r("1234")->split('')->join(',')();
echo r([1,2,3])->indexOf(2);
echo x()->split(....)->join(....)->x([1,2,3]);

JS PHP 7
JSObject=function(i){
  this.me=i;
};
JSObject.prototype={
  hi:function(a){
    return a;
  }
};
$f = new JSObject("AJ");
$f->hi();
class JSObject {
  function __construct($members = array()) {
    foreach ($members as $name => $value) {
      $this->$name = $value;
    }
  }
  function __call($name, $args) {
    if (is_callable($this->$name)) {
      array_unshift($args, $this);
      return call_user_func_array($this->$name, $args);
    }
  }
}
$f = new JSObject(array(
  'me' => "me",
  'hi'  => function($s) {
    return $s;
  }
));
echo $f->hi();
class SubArray extends Array {
    constructor(...args) { 
        super(...args); 
    }
}
Array.isArray(new SubArray); //true
//can't really effectively sub class an error 
class CaseInsensitiveArray extends ArrayObject {
    public function __construct($input = array(), $flags = 0, $iterator_class =     'ArrayIterator') {
        if (isset($input) && is_array($input)) {
            $tmpargs = func_get_args();
            $tmpargs[0] = array_change_key_case($tmpargs[0], CASE_LOWER);
            return call_user_func_array(array('parent', __FUNCTION__), $tmp    args);
        }
        return call_user_func_array(array('parent', __FUNCTION__), func_get_args());
    }
}
$b = new CaseInsensitiveArray(array());
echo "is array: ".is_array($b);  // false
var return_true = 'some apples'.match(/.*/i);
$return_1 = mb_ereg_match(".*a", "some apples");

Symbolic PHP was me experimenting making it similar to mathematica which failed miserably.

php -v
Symbolic php php JSON AST
<?php
echo 'Hi', 'World';
hello\world('foo', 'bar' . 'baz');
array(
    0: Stmt_Echo(
        exprs: array(
            0: Scalar_String(
                value: Hi
            )
            1: Scalar_String(
                value: World
            )
        )
    )
    1: Expr_FuncCall(
        name: Name(
            parts: array(
                0: hello
                1: world
            )
        )
        args: array(
            0: Arg(
                value: Scalar_String(
                    value: foo
                )
                byRef: false
            )
            1: Arg(
                value: Expr_Concat(
                    left: Scalar_String(
                        value: bar
                    )
                    right: Scalar_String(
                        value: baz
                    )
                )
                byRef: false
            )
        )
    )
)
[
    {
        "nodeType": "Stmt_Echo",
        "exprs": [
            {
                "nodeType": "Scalar_String",
                "value": "Hello ",
                "attributes": {
                    "startLine": 1,
                    "endLine": 1,
                    "kind": 1
                }
            },
            {
                "nodeType": "Expr_FuncCall",
                "name": {
                    "nodeType": "Name",
                    "parts": [
                        "hi",
                        "getTarget"
                    ],
                    "attributes": {
                        "startLine": 1,
                        "endLine": 1
                    }
                },
                "args": [],
                "attributes": {
                    "startLine": 1,
                    "endLine": 1
                }
            }
        ],
        "attributes": {
            "startLine": 1,
            "endLine": 1
        }
    }
]
o.Method(args); o\[Dot]Method[args]; o@Method[args];
//Inner Class
Box.Filler f = new Box.Filler(args);
Box$Filler@f = new["java.swing.Box$Filler", args]
f = JavaNew["java.swing.Box$Filler", args]
o.prop = 1; val = obj.prop;
o\[Dot]prop = 1; val = obj\[Dot]prop;
o@prop = 1;val = o@prop;

					
MyClass`StaticMethod[args];
MyClass.StaticPropertyOrField = 1;
value = MyClass.StaticPropertyOrField;
MyClass`StaticPropertyOrField = 1;
value = MyClass`StaticPropertyOrField;
int i = 1;
double d = 2;
int[] anArray;
anArray = new int[10][20];
int \[CircleDot] i = 23;
double \[CircleDot] d = double \[CircleDot] 2;
anArray = int \[Colon] 10;
i = 23;
public class MyClass {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
  public void Method(){
System.out.println("Method")} public static void staticMethod(){ System.out.println("Static method"); } public MyClass(){
System.out.println("Test");} }
public@class@MyClass[
  public@static@void@main[String@args[]][
    System@out@println["Hello, World");
  ],
  public@MyClass[][
    System@out@println[""];
  ]
]
public class MyClass[
  public static void main[String args[]][
    System:out:println["Hello, World");
  ],
  public@MyClass[][
    System@out@println[""];
  ]
]
For, If, Else,