-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
178 lines (134 loc) · 3.01 KB
/
test.php
File metadata and controls
178 lines (134 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
namespace App;
class Router {
public function __construct() {
echo "Im init!";
echo '<br>';
}
public function myFunction() : int {
echo "Hello from inside myFunction in class Router!";
echo '<br>';
$returns = 10;
return $returns;
}
}
function RunTests($id) : void {
$hello = "Hello ";
$example_html = '<h1>' . $hello . "World" . '</h1>';
echo $example_html;
echo '<code>';
function ExampleFunction() : int {
echo "I return (expect 1): ";
return 1;
}
$hi = ExampleFunction();
echo $hi;
echo '<br>';
$router = new Router();
$b = $router->myFunction();
// If
if ($b == 10) {
echo "If works";
echo '<br>';
} else {
echo "If failed";
// ?panic;
}
// While
while ($b != 10) {
echo $b;
$b = $b + 1;
}
$array = ["Hello", "World", "three"];
// Foreach
foreach ($array as $value) {
echo $value;
echo '<br>';
}
echo '</code>';
}
RunTests(1);
class Robot
{
public $greeting;
// $greeting = "a";
public function __construct()
{
$this->greeting = "Hello";
}
public function greet()
{
return $this->greeting;
}
public function bye()
{
return 'Good bye!';
}
public function wrap()
{
echo "+++++++";
}
}
class Android extends Robot
{
public function __construct()
{
// ? debug;
$this->greeting = "Hi!";
}
}
// Instead of this
// debug_print_backtrace();
// Use this
// ?debug;
$robot = new Robot();
$a = $robot->greet(); // Hello
echo "Robot: " . $a . " Expected: " . $robot->greeting;
echo "</br>";
$android = new Android();
$b = $android->greet(); // Hi!
echo "Android: " . $b . " Expected: " . $android->greeting;
echo "</br>";
$android->bye(); // Good bye!
class YourApp {
public $greeting;
public function __construct() {
$this->greeting = "Welcome to NoPHP";
}
public function welcome() {
echo "<h1>" . $this->greeting . "</h1>";
}
}
$app = new YourApp();
$app->welcome();
// ?debug;
session_start(); // Regardless of this call, if a session exists, it will be reused in this scope.
// As to prevent throwing around an object from Python in scopes, a singleton is used.
$_SESSION["aa"] = "cc";
echo $_SESSION["aa"];
function test_scopes_for_session()
{
$_SESSION["aa"] = "bb";
echo $_SESSION["aa"];
}
test_scopes_for_session();
echo $_SESSION["aa"];
echo "<br>" . "Expected output: cc bb bb";
require_once("example.php");
use Example;
echo "<br>" . Example\greet(2000);
echo "<br>" . Example\greet(1000);
// Try to fix function scope issues
class HelloWorld {
public function run() : string {
return <h1>"Hello, World!"</h1>;
}
public function displayOutput() {
echo $this->run();
}
}
// Create an instance of the class
$helloWorld = new HelloWorld();
// Display the output
$helloWorld->displayOutput();
?>