phptest - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of phptest.php
- <?php
- declare(strict_types=1);
- namespace Agis2;
- class Auth
- {
- public function __construct(private string $username, private string $password)
- {
- }
- public function getUsername(): string
- {
- return $this->username;
- }
- }
- class Contact
- {
- public function __construct(private string $phone, private string $email)
- {
- }
- public function getEmail(): string
- {
- return $this->email;
- }
- public function setEmail(string $email): void
- {
- $this->email = $email;
- }
- public function getPhone(): string
- {
- return $this->phone;
- }
- }
- class User
- {
- public function __construct(private Auth $auth, private Contact $contact)
- {
- }
- public function getAuth(): Auth
- {
- return $this->auth;
- }
- public function getEmail(): string
- {
- return $this->contact->getEmail();
- }
- public function setEmail(string $email): void
- {
- $this->contact->setEmail($email);
- }
- public function sendEmail(string $subject, string $message): void
- {
- EmailSender::send($this->getEmail(), $subject, $message);
- }
- public function sendSms(string $message): void
- {
- PhoneSender::send($this->contact->getPhone(), $message);
- }
- public function createUser(string $username, string $password, string $phone, string $email): self
- {
- return new self(
- new Auth($username, $password),
- new Contact($phone, $email),
- );
- }
- public static function parseFile(string $path): \Generator
- {
- $handle = fopen($path, 'r');
- while (!feof($handle)) {
- yield trim(fgets($handle));
- }
- fclose($handle);
- }
- public static function loadFromFile(string $path): array
- {
- $users = [];
- foreach (self::parseFile($path) as $row) {
- [$username, $password, $phone, $email] = explode(';', $row);
- $users[] = $this->createUser($username, $password, $phone, $email);
- }
- return $users;
- }
- }
File Description
- phptest
- PHP Code
- 15 May-2023
- 2.02 Kb
You can Share it:
Latest PHP Pastes