Assume private visibility for all class members by default.
The build was successful. Details

In most (all?) modern OOP languages class members visibility is assumed to be private and programmer has to consciously set it to public or protected. PHP has the different approach what can cause a security flaws in written scripts. AerScript will not follow this way, as it seems to be conceptually broken.
This commit is contained in:
Rafal Kupiec 2019-05-17 08:40:41 +02:00
parent 48ccd7fef0
commit 55acf8111f
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
41 changed files with 72 additions and 84 deletions

View File

@ -3833,8 +3833,8 @@ static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags) {
"Unexpected token '%z'. Expecting attribute or method declaration inside class '%z'", "Unexpected token '%z'. Expecting attribute or method declaration inside class '%z'",
&pGen->pIn->sData, pName); &pGen->pIn->sData, pName);
} }
/* Assume public visibility */ /* Assume private visibility */
iProtection = PH7_KEYWORD_PUBLIC; iProtection = PH7_KEYWORD_PRIVATE;
iAttrflags = 0; iAttrflags = 0;
/* Extract the current keyword */ /* Extract the current keyword */
nKwrd = SX_PTR_TO_INT(pGen->pIn->pUserData); nKwrd = SX_PTR_TO_INT(pGen->pIn->pUserData);

View File

@ -13,16 +13,9 @@ class Program {
return $filtered; return $filtered;
} }
void main() { public void main() {
int[] $filtered = $this->filter($this->condition, $this->numbers); int[] $filtered = $this->filter($this->condition, $this->numbers);
var_dump($filtered); var_dump($filtered);
} }
} }
/*
* Should output
Array ( [0] => 897 [1] => 123 )
*/

View File

@ -1,6 +1,6 @@
class Program { class Program {
int main() { public int main() {
int[] $arr1; int[] $arr1;
int[] $arr2 = {0, 0}; int[] $arr2 = {0, 0};
float[] $arr3 = {1, 4.5}; float[] $arr3 = {1, 4.5};

View File

@ -4,7 +4,7 @@ class Program {
assert("is_bool($param);"); assert("is_bool($param);");
} }
void main() { public void main() {
callback $assert_fail = void(string $file, int $line, string $code) { callback $assert_fail = void(string $file, int $line, string $code) {
print("Assertion failed ...\n"); print("Assertion failed ...\n");
}; };

View File

@ -68,7 +68,7 @@ class Base32 {
} }
class Program { class Program {
void main() { public void main() {
var_dump(Base32::encode('Test String'), Base32::encode('DS27DEC985'), Base32::encode('AerScript rocks!')); var_dump(Base32::encode('Test String'), Base32::encode('DS27DEC985'), Base32::encode('AerScript rocks!'));
var_dump(Base32::decode('KRSXG5BAKN2HE2LOM4======'), Base32::decode('IRJTEN2EIVBTSOBV'), Base32::decode('IFSXEU3DOJUXA5BAOJXWG23TEE======')); var_dump(Base32::decode('KRSXG5BAKN2HE2LOM4======'), Base32::decode('IRJTEN2EIVBTSOBV'), Base32::decode('IFSXEU3DOJUXA5BAOJXWG23TEE======'));
} }

View File

@ -11,7 +11,7 @@ class Program {
return ltrim($rtnval); return ltrim($rtnval);
} }
void main() { public void main() {
var_dump($this->fmt_binary(2541)); var_dump($this->fmt_binary(2541));
} }
} }

View File

@ -78,7 +78,7 @@ class Brainfuck {
class Program { class Program {
void main() { public void main() {
object $bf; object $bf;
string $code; string $code;
resource $dir; resource $dir;

View File

@ -1,6 +1,6 @@
class Program { class Program {
void main(string[] $args) { public void main(string[] $args) {
callback $y = void() { callback $y = void() {
callback $a = 'printf'; callback $a = 'printf';
$a("I'm alive\n"); $a("I'm alive\n");

View File

@ -15,14 +15,9 @@ class Program {
return $result; return $result;
} }
void main() { public void main() {
string $str = 'Example text'; string $str = 'Example text';
print($this->center_text($str)); print($this->center_text($str));
} }
} }
/* Should output
---------------This is some text------------
*/

View File

@ -7,12 +7,12 @@ class Test2 extends Test1 {
class Program { class Program {
object $t; object $t;
void test(Test1 $t = new Test2) { private void test(Test1 $t = new Test2) {
$this->t = $t; $this->t = $t;
var_dump($this->t); var_dump($this->t);
} }
void main() { public void main() {
$this->test(); $this->test();
} }

View File

@ -13,7 +13,7 @@ class Button {
$this->DoAfterClick(); $this->DoAfterClick();
} }
private void DoBeforeClick() { private void DoBeforeClick() {
if($this->OnBeforeClick) { if($this->OnBeforeClick) {
callback $event = $this->OnBeforeClick; callback $event = $this->OnBeforeClick;
$event($this); $event($this);
@ -31,7 +31,7 @@ class Button {
class Program { class Program {
void main() { public void main() {
object $MyWidget = new Button(); object $MyWidget = new Button();
$MyWidget->OnBeforeClick = void(object $Sender) { print($Sender->Name + ' (Before Click)'); }; $MyWidget->OnBeforeClick = void(object $Sender) { print($Sender->Name + ' (Before Click)'); };
$MyWidget->OnAfterClick = void(object $Sender) { print($Sender->Name + ' (After Click)'); }; $MyWidget->OnAfterClick = void(object $Sender) { print($Sender->Name + ' (After Click)'); };

View File

@ -22,7 +22,7 @@ class Operations {
class Program { class Program {
void main() { public void main() {
callback $fn; callback $fn;
object $op = new Operations(); object $op = new Operations();
$fn = $op->ops(6, 7, 'ADD'); $fn = $op->ops(6, 7, 'ADD');

View File

@ -24,7 +24,7 @@ class Program {
return false; return false;
} }
int main() { public int main() {
static float $f = 4 + 2.4 * 9.1; static float $f = 4 + 2.4 * 9.1;
var_dump($this->MY_CONST); var_dump($this->MY_CONST);
var_dump($this->callback_test); var_dump($this->callback_test);

View File

@ -1,12 +1,12 @@
class Program { class Program {
void test(int $a = (int(int $a, int $b, int $c){return $a+$b+$c;})(14, 10+2, 15), int $b = 0, int $c = 98) { private void test(int $a = (int(int $a, int $b, int $c){return $a+$b+$c;})(14, 10+2, 15), int $b = 0, int $c = 98) {
print($a + PHP_EOL); print($a + PHP_EOL);
print($b + PHP_EOL); print($b + PHP_EOL);
print($c + PHP_EOL); print($c + PHP_EOL);
} }
void main() { public void main() {
$this->test(); $this->test();
$this->test(512); $this->test(512);
$this->test(1024, 32); $this->test(1024, 32);

View File

@ -3,12 +3,12 @@ define TEST_CONSTANT 'This is a global constant';
class Program { class Program {
const TEST_CONSTANT = 'This is a class constant'; const TEST_CONSTANT = 'This is a class constant';
void constant_test() { private void constant_test() {
const TEST_CONSTANT = 'This is a local constant'; const TEST_CONSTANT = 'This is a local constant';
var_dump(TEST_CONSTANT); var_dump(TEST_CONSTANT);
} }
void main() { public void main() {
int $var = 69; int $var = 69;
var_dump(TEST_CONSTANT); var_dump(TEST_CONSTANT);
$this->constant_test(); $this->constant_test();

View File

@ -1,6 +1,6 @@
class Program { class Program {
void main() { public void main() {
$this->b($this->a('First A'), $this->a('Second A'), $this->a('Third A')); $this->b($this->a('First A'), $this->a('Second A'), $this->a('Third A'));
} }

View File

@ -1,10 +1,10 @@
class Test1 { class Test1 {
void __construct() { public void __construct() {
print("Test1::__construct() called.\n"); print("Test1::__construct() called.\n");
} }
void __destruct() { public void __destruct() {
print("Test1::__destruct() called.\n"); print("Test1::__destruct() called.\n");
} }
@ -12,12 +12,12 @@ class Test1 {
class Test2 extends Test1 { class Test2 extends Test1 {
void __construct() { public void __construct() {
print("Test2::__construct() called.\n"); print("Test2::__construct() called.\n");
$parent->__construct(); $parent->__construct();
} }
void __destruct() { public void __destruct() {
print("Test2::__destruct() called.\n"); print("Test2::__destruct() called.\n");
$parent->__destruct(); $parent->__destruct();
} }
@ -27,16 +27,16 @@ class Test2 extends Test1 {
class Program { class Program {
object $test; object $test;
void __construct() { public void __construct() {
print("Program::__construct() called.\n"); print("Program::__construct() called.\n");
$this->test = new Test1(); $this->test = new Test1();
} }
void __destruct() { public void __destruct() {
print("Program::__destruct() called.\n"); print("Program::__destruct() called.\n");
} }
void main() { public void main() {
print("Program::main() called.\n"); print("Program::main() called.\n");
object $test = new Test2(); object $test = new Test2();
} }

View File

@ -15,7 +15,7 @@ class NewException extends Exception {
class Program { class Program {
void main() { public void main() {
callback $handler = void(Exception $e) { callback $handler = void(Exception $e) {
ExceptionHandler::handleException($e); ExceptionHandler::handleException($e);
}; };

View File

@ -16,7 +16,7 @@ class Dog {
class Program { class Program {
void main() { public void main() {
object $dog = new Dog('Alex', 'red'); object $dog = new Dog('Alex', 'red');
callback $c = $dog->greet('Hello'); callback $c = $dog->greet('Hello');
$c(); $c();

View File

@ -1,13 +1,13 @@
class Program { class Program {
int factorial(int $num) { private int factorial(int $num) {
if($num == 0 || $num == 1) if($num == 0 || $num == 1)
return 1; return 1;
else else
return $num * $this->factorial($num - 1); return $num * $this->factorial($num - 1);
} }
void main() { public void main() {
int $num = 7; int $num = 7;
print('Factorial of ', $num, ' is ', $this->factorial($num), '.'); print('Factorial of ', $num, ' is ', $this->factorial($num), '.');
} }

View File

@ -1,11 +1,11 @@
class Circle { class Circle {
void draw() { public void draw() {
print("Circle\n"); print("Circle\n");
} }
} }
class Square { class Square {
void draw() { public void draw() {
print("Square\n"); print("Square\n");
} }
} }
@ -21,7 +21,7 @@ class Program {
} }
} }
void main() { public void main() {
$this->ShapeFactoryMethod("Circle")->draw(); $this->ShapeFactoryMethod("Circle")->draw();
$this->ShapeFactoryMethod("Square")->draw(); $this->ShapeFactoryMethod("Square")->draw();
} }

View File

@ -1,6 +1,6 @@
class Test { class Test {
void goto_test1() { public void goto_test1() {
int $i = 0; int $i = 0;
a: a:
print("Foo $i\n"); print("Foo $i\n");
@ -12,7 +12,7 @@ class Test {
print("Bar $i\n\n"); print("Bar $i\n\n");
} }
void goto_test2(int $a = 2) { public void goto_test2(int $a = 2) {
switch($a) { switch($a) {
case 1: case 1:
print("\$a is 1\n\n"); print("\$a is 1\n\n");
@ -30,7 +30,7 @@ class Test {
out: out:
} }
void goto_test3() { public void goto_test3() {
int $a = 10; int $a = 10;
a: a:
$a--; $a--;
@ -41,7 +41,7 @@ class Test {
print("\n"); print("\n");
} }
void goto_test4() { public void goto_test4() {
string[] $headers = {'subject', 'bcc', 'to', 'cc', 'date', 'sender'}; string[] $headers = {'subject', 'bcc', 'to', 'cc', 'date', 'sender'};
int $pos = 0; int $pos = 0;
int $c; int $c;
@ -67,11 +67,11 @@ class Test {
class Program { class Program {
private object $test; private object $test;
void __construct() { public void __construct() {
$this->test = new Test(); $this->test = new Test();
} }
void main() { public void main() {
$this->test->goto_test1(); $this->test->goto_test1();
$this->test->goto_test2(); $this->test->goto_test2();
$this->test->goto_test3(); $this->test->goto_test3();

View File

@ -1,6 +1,6 @@
class Program { class Program {
string num2alpha(int $n) { private string num2alpha(int $n) {
string $r = ''; string $r = '';
for(int $i = 1; $n >= 0 && $i < 10; $i++) { for(int $i = 1; $n >= 0 && $i < 10; $i++) {
$r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) + $r; $r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) + $r;
@ -9,7 +9,7 @@ class Program {
return $r; return $r;
} }
int alpha2num(string $a) { private int alpha2num(string $a) {
int $r = 0; int $r = 0;
int $l = strlen($a); int $l = strlen($a);
for(int $i = 0; $i < $l; $i++) { for(int $i = 0; $i < $l; $i++) {
@ -18,7 +18,7 @@ class Program {
return (int) $r - 1; return (int) $r - 1;
} }
void main() { public void main() {
import('math'); import('math');
var_dump($this->alpha2num("Salut"), $this->num2alpha(1723), $this->num2alpha(9854), $this->alpha2num("Base64")); var_dump($this->alpha2num("Salut"), $this->num2alpha(1723), $this->num2alpha(9854), $this->alpha2num("Base64"));
} }

View File

@ -10,7 +10,7 @@ class Program {
return hexdec($hexipbang[0]) + '.' + hexdec($hexipbang[1]) + '.' + hexdec($hexipbang[2]) + '.' + hexdec($hexipbang[3]); return hexdec($hexipbang[0]) + '.' + hexdec($hexipbang[1]) + '.' + hexdec($hexipbang[2]) + '.' + hexdec($hexipbang[3]);
} }
void main() { public void main() {
string $localhost = $this->encode_ip('127.0.0.1'); string $localhost = $this->encode_ip('127.0.0.1');
print("127.0.0.1 ==> $localhost\n"); print("127.0.0.1 ==> $localhost\n");
string $router = $this->encode_ip('192.168.2.1'); string $router = $this->encode_ip('192.168.2.1');

View File

@ -1,5 +1,5 @@
final class Program { final class Program {
void main() { public void main() {
var_dump(function_exists('dummy_function')); var_dump(function_exists('dummy_function'));
var_dump(import('dummy')); var_dump(import('dummy'));
var_dump(function_exists('dummy_function')); var_dump(function_exists('dummy_function'));

View File

@ -1,6 +1,6 @@
class Program { class Program {
void main() { public void main() {
int[] $numbers = {'five' => 5, 'six' => 6, 'seven' => 7, 'eight' => 8, 'nine' => 9, 'zero' => 0}; int[] $numbers = {'five' => 5, 'six' => 6, 'seven' => 7, 'eight' => 8, 'nine' => 9, 'zero' => 0};
string[] $days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; string[] $days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
foreach(string $key => int $numeric in $numbers) { foreach(string $key => int $numeric in $numbers) {

View File

@ -1,15 +1,15 @@
class Luhn { class Luhn {
private string $number; private string $number;
string getNumber() { public string getNumber() {
return $this->number; return $this->number;
} }
void setNumber(string $number) { public void setNumber(string $number) {
$this->number = $number; $this->number = $number;
} }
bool validate() { public bool validate() {
string $sum; string $sum;
string $revNumber; string $revNumber;
int $len; int $len;
@ -26,7 +26,7 @@ class Luhn {
class Program { class Program {
private const NUMBERS = {'3788803280', '6487308345', '5443489710530865', '5539266155200609', '4024007151066296', '4345234978'}; private const NUMBERS = {'3788803280', '6487308345', '5443489710530865', '5539266155200609', '4024007151066296', '4345234978'};
void main() { public void main() {
int $i, $nums = sizeof($this->NUMBERS); int $i, $nums = sizeof($this->NUMBERS);
object $luhn = new Luhn(); object $luhn = new Luhn();

View File

@ -1,6 +1,6 @@
class Dog { class Dog {
void __invoke() { public void __invoke() {
print("I am a dog!\n"); print("I am a dog!\n");
} }
} }
@ -8,7 +8,7 @@ class Dog {
class Program { class Program {
void main() { public void main() {
object $dog = new Dog(); object $dog = new Dog();
$dog(); $dog();
} }

View File

@ -53,7 +53,7 @@ class TestE {
class Program extends TestE, TestD, TestC, TestB, TestA implements IntA, IntB { class Program extends TestE, TestD, TestC, TestB, TestA implements IntA, IntB {
void main() { public void main() {
$this->test_a(); $this->test_a();
$this->test_b(); $this->test_b();
$this->test_c(); $this->test_c();

View File

@ -8,7 +8,7 @@ class Program {
return {'callme' => void() { print("Hello world\n"); }}; return {'callme' => void() { print("Hello world\n"); }};
} }
void main() { public void main() {
callback[] $constr = {'print'}; callback[] $constr = {'print'};
print($this->testArray()['Machine'] + "\n"); print($this->testArray()['Machine'] + "\n");
$this->testCallback()['callme'](); $this->testCallback()['callme']();

View File

@ -1,16 +1,16 @@
class Test { class Test {
void __construct(string $a) { public void __construct(string $a) {
print("$a\n"); print("$a\n");
} }
void __construct(int $a, int $b) { public void __construct(int $a, int $b) {
print("$a + $b = ", $a + $b, "\n"); print("$a + $b = ", $a + $b, "\n");
} }
} }
class Program { class Program {
void main() { public void main() {
object $a, $b; object $a, $b;
$a = new Test('Hello world!'); $a = new Test('Hello world!');
$b = new Test(4, 7); $b = new Test(4, 7);

View File

@ -1,14 +1,14 @@
class Program { class Program {
void count(int $a, int $b) { public void count(int $a, int $b) {
print("Counting 2 integers: $a + $b = ", $a + $b, "\n"); print("Counting 2 integers: $a + $b = ", $a + $b, "\n");
} }
void count(float $a, float $b) { public void count(float $a, float $b) {
print("Counting 2 floats: $a + $b = ", $a + $b, "\n"); print("Counting 2 floats: $a + $b = ", $a + $b, "\n");
} }
void main() { public void main() {
$this->count(4.3, 5.7); $this->count(4.3, 5.7);
$this->count(6, 4); $this->count(6, 4);
} }

View File

@ -8,7 +8,7 @@ class Program {
return $result; return $result;
} }
void main() { public void main() {
int $z; int $z;
int $y = 5; int $y = 5;
for(int $x = 0; $x < $y; $x++) { for(int $x = 0; $x < $y; $x++) {

View File

@ -18,7 +18,7 @@ class Program {
return $retArray; return $retArray;
} }
void main() { public void main() {
string $path = '/my//stupid//path/to///some/file.php'; string $path = '/my//stupid//path/to///some/file.php';
print_r($this->parsePathComponents($path)); print_r($this->parsePathComponents($path));

View File

@ -1,10 +1,10 @@
class Program { class Program {
void add_by_ref(int &$val) { private void add_by_ref(int &$val) {
$val += 7; $val += 7;
} }
void main() { public void main() {
int $num = 7; int $num = 7;
$this->add_by_ref($num); $this->add_by_ref($num);
var_dump($num); var_dump($num);

View File

@ -1,6 +1,6 @@
class Program { class Program {
string cycle(char $a, char $b, int $i = 0) { private string cycle(char $a, char $b, int $i = 0) {
static bool[] $switches; static bool[] $switches;
if($switches[$i]) if($switches[$i])
$switches[$i] = !$switches[$i]; $switches[$i] = !$switches[$i];
@ -9,7 +9,7 @@ class Program {
return ($switches[$i]) ? $a : $b; return ($switches[$i]) ? $a : $b;
} }
void main() { public void main() {
for(int $i = 1; $i < 3; $i++) { for(int $i = 1; $i < 3; $i++) {
print($i + $this->cycle('a', 'b') + PHP_EOL); print($i + $this->cycle('a', 'b') + PHP_EOL);
for(int $j = 1; $j < 5; $j++) { for(int $j = 1; $j < 5; $j++) {

View File

@ -1,6 +1,6 @@
class Program { class Program {
void main() { public void main() {
int $a = 1; int $a = 1;
switch($a) { switch($a) {
case 0: case 0:

View File

@ -14,7 +14,7 @@ class Program {
return strtr($str, $table); return strtr($str, $table);
} }
void main() { public void main() {
var_dump($this->normalize("ÿĆ Welcome ÂëÑ Žöø Ŕ")); var_dump($this->normalize("ÿĆ Welcome ÂëÑ Žöø Ŕ"));
} }

View File

@ -24,7 +24,7 @@ class StringTokenizer {
} }
class Program { class Program {
void main() { public void main() {
string $str = "This is:@\t\n a TEST!"; string $str = "This is:@\t\n a TEST!";
string $delim = " !@:\t\n"; string $delim = " !@:\t\n";
object $st = new StringTokenizer($str, $delim); object $st = new StringTokenizer($str, $delim);

View File

@ -26,7 +26,7 @@ class Program {
var_dump(is_void($value)); var_dump(is_void($value));
} }
void main() { public void main() {
object $objval; object $objval;
void $voidval; void $voidval;
$this->testChar('c'); $this->testChar('c');

View File

@ -1,6 +1,6 @@
class Program { class Program {
void main() { public void main() {
mixed $foo; mixed $foo;
$foo = '0'; $foo = '0';
var_dump($foo); var_dump($foo);