diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
| commit | 5a8dbc6347b3541e84fe669b22c17ad3b715e258 (patch) | |
| tree | b148c450939688caaaeb4adac6f2faa1eaffe649 /samples/test.php | |
| download | qwe-editor-5a8dbc6347b3541e84fe669b22c17ad3b715e258.tar.gz | |
Engage!
Diffstat (limited to 'samples/test.php')
| -rw-r--r-- | samples/test.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/samples/test.php b/samples/test.php new file mode 100644 index 0000000..2fc5bad --- /dev/null +++ b/samples/test.php @@ -0,0 +1,72 @@ +<?php + +// A simple PHP script + +namespace App; + +use Exception; + +class User { + private $name; + private $email; + + public function __construct($name, $email) { + $this->name = $name; + $this->email = $email; + } + + public function getName() { + return $this->name; + } + + public function getEmail() { + return $this->email; + } + + public function save() { + // Simulate saving to database + echo "Saving user {$this->name} to database.\n"; + return true; + } +} + +function processUsers($users) { + foreach ($users as $user) { + try { + if ($user->save()) { + echo "User saved successfully.\n"; + } + } catch (Exception $e) { + echo "Error: " . $e->getMessage() . "\n"; + } + } +} + +// Data array +$users_data = [ + ['name' => 'Alice', 'email' => 'alice@example.com'], + ['name' => 'Bob', 'email' => 'bob@example.com'], +]; + +$user_objects = []; + +// Loop and create objects +if (!empty($users_data)) { + foreach ($users_data as $data) { + $user_objects[] = new User($data['name'], $data['email']); + } +} + +// Call function +processUsers($user_objects); + +// Alternative syntax for control structures +$count = 0; +while ($count < 3): + echo "Count is $count\n"; + $count++; +endwhile; + +echo "Script completed.\n"; + +?> |
