Browse Source

Assume private visibility for all class members by default.

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.
release/v0.1
Rafal Kupiec 3 years ago
parent
commit
55acf8111f
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
  1. 4
      engine/compiler.c
  2. 9
      tests/anon_filter.aer
  3. 2
      tests/array_subscription.aer
  4. 2
      tests/assertion_test.aer
  5. 2
      tests/base32_test.aer
  6. 2
      tests/bin_format.aer
  7. 2
      tests/brainfuck_interpreter.aer
  8. 2
      tests/callback_function.aer
  9. 7
      tests/center_text.aer
  10. 4
      tests/class_instance_arg.aer
  11. 4
      tests/closure_event.aer
  12. 2
      tests/closure_test.aer
  13. 2
      tests/complex_expressions.aer
  14. 4
      tests/complex_expressions2.aer
  15. 4
      tests/constants_access.aer
  16. 2
      tests/debug_backtrace.aer
  17. 14
      tests/entry_point.aer
  18. 2
      tests/exception_handler.aer
  19. 2
      tests/extended_closure.aer
  20. 4
      tests/factorial_test.aer
  21. 6
      tests/factory_objects.aer
  22. 12
      tests/goto_statement.aer
  23. 6
      tests/int2alpha_test.aer
  24. 2
      tests/ip_addr_enc_dec.aer
  25. 2
      tests/load_module.aer
  26. 2
      tests/loop_foreach_test.aer
  27. 8
      tests/luhn_verify.aer
  28. 4
      tests/magic_method.aer
  29. 2
      tests/multiple_inheritance.aer
  30. 2
      tests/operators_precedence.aer
  31. 6
      tests/overloading_constructor.aer
  32. 6
      tests/overloading_methods.aer
  33. 2
      tests/pascal_triangle.aer
  34. 2
      tests/path_split.aer
  35. 4
      tests/reference_test.aer
  36. 4
      tests/static_var.aer
  37. 2
      tests/switch_block.aer
  38. 2
      tests/text_normalize.aer
  39. 2
      tests/tokenizer.aer
  40. 2
      tests/type_hinting.aer
  41. 2
      tests/type_juggle.aer

4
engine/compiler.c

@ -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'",
&pGen->pIn->sData, pName);
}
/* Assume public visibility */
iProtection = PH7_KEYWORD_PUBLIC;
/* Assume private visibility */
iProtection = PH7_KEYWORD_PRIVATE;
iAttrflags = 0;
/* Extract the current keyword */
nKwrd = SX_PTR_TO_INT(pGen->pIn->pUserData);

9
tests/anon_filter.aer

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

2
tests/array_subscription.aer

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

2
tests/assertion_test.aer

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

2
tests/base32_test.aer

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

2
tests/bin_format.aer

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

2
tests/brainfuck_interpreter.aer

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

2
tests/callback_function.aer

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

7
tests/center_text.aer

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

4
tests/class_instance_arg.aer

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

4
tests/closure_event.aer

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

2
tests/closure_test.aer

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

2
tests/complex_expressions.aer

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

4
tests/complex_expressions2.aer

@ -1,12 +1,12 @@
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($b + PHP_EOL);
print($c + PHP_EOL);
}
void main() {
public void main() {
$this->test();
$this->test(512);
$this->test(1024, 32);

4
tests/constants_access.aer

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

2
tests/debug_backtrace.aer

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

14
tests/entry_point.aer

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

2
tests/exception_handler.aer

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

2
tests/extended_closure.aer

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

4
tests/factorial_test.aer

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

6
tests/factory_objects.aer

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

12
tests/goto_statement.aer

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

6
tests/int2alpha_test.aer

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

2
tests/ip_addr_enc_dec.aer

@ -10,7 +10,7 @@ class Program {
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');
print("127.0.0.1 ==> $localhost\n");
string $router = $this->encode_ip('192.168.2.1');

2
tests/load_module.aer

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

2
tests/loop_foreach_test.aer

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

8
tests/luhn_verify.aer

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

4
tests/magic_method.aer

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

2
tests/multiple_inheritance.aer

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

2
tests/operators_precedence.aer

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

6
tests/overloading_constructor.aer

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

6
tests/overloading_methods.aer

@ -1,14 +1,14 @@
class Program {
void count(int $a, int $b) {
public void count(int $a, int $b) {
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");
}
void main() {
public void main() {
$this->count(4.3, 5.7);
$this->count(6, 4);
}

2
tests/pascal_triangle.aer

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

2
tests/path_split.aer

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

4
tests/reference_test.aer

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

4
tests/static_var.aer

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

2
tests/switch_block.aer

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

2
tests/text_normalize.aer

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

2
tests/tokenizer.aer

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

2
tests/type_hinting.aer

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

2
tests/type_juggle.aer

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

Loading…
Cancel
Save