-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
188 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
class Person | ||
{ | ||
// A "virtual" property. It may not be set explicitly. | ||
public string $fullName { | ||
get => $this->firstName . ' ' . $this->lastName; | ||
} | ||
|
||
// All write operations go through this hook, and the result is what is written. | ||
// Read access happens normally. | ||
public string $firstName { | ||
set => ucfirst(strtolower($value)); | ||
} | ||
|
||
// All write operations go through this hook, which has to write to the backing value itself. | ||
// Read access happens normally. | ||
public string $lastName { | ||
set { | ||
if (strlen($value) < 2) { | ||
throw new \InvalidArgumentException('Too short'); | ||
} | ||
$this->lastName = $value; | ||
} | ||
} | ||
} | ||
|
||
$p = new Person(); | ||
|
||
$p->firstName = 'peter'; | ||
print $p->firstName; // Prints "Peter" | ||
$p->lastName = 'Peterson'; | ||
print $p->fullName; // Prints "Peter Peterson" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
;; -*- mode: emacs-lisp -*- | ||
(("<?php" . php-php-tag) | ||
("\n\n") | ||
("class" . php-class-declaration) | ||
(" ") | ||
("Person" . font-lock-type-face) | ||
("\n{\n ") | ||
("// " . font-lock-comment-delimiter-face) | ||
("A \"virtual\" property. It may not be set explicitly.\n" . font-lock-comment-face) | ||
(" ") | ||
("public" . php-keyword) | ||
(" ") | ||
("string" . php-class) | ||
(" ") | ||
("$" . php-variable-sigil) | ||
("fullName" . php-variable-name) | ||
(" {\n ") | ||
("get" . php-builtin) | ||
(" ") | ||
("=" . php-assignment-op) | ||
(">" . php-comparison-op) | ||
(" ") | ||
("$" . php-this-sigil) | ||
("this" . php-this) | ||
("->" . php-object-op) | ||
("firstName" . php-property-name) | ||
(" . ") | ||
("' '" . php-string) | ||
(" . ") | ||
("$" . php-this-sigil) | ||
("this" . php-this) | ||
("->" . php-object-op) | ||
("lastName" . php-property-name) | ||
(";\n }\n\n ") | ||
("// " . font-lock-comment-delimiter-face) | ||
("All write operations go through this hook, and the result is what is written.\n" . font-lock-comment-face) | ||
(" ") | ||
("// " . font-lock-comment-delimiter-face) | ||
("Read access happens normally.\n" . font-lock-comment-face) | ||
(" ") | ||
("public" . php-keyword) | ||
(" ") | ||
("string" . php-class) | ||
(" ") | ||
("$" . php-variable-sigil) | ||
("firstName" . php-variable-name) | ||
(" {\n ") | ||
("set" . php-builtin) | ||
(" ") | ||
("=" . php-assignment-op) | ||
(">" . php-comparison-op) | ||
(" ") | ||
("ucfirst" . php-function-call-traditional) | ||
("(") | ||
("strtolower" . php-function-call-traditional) | ||
("(") | ||
("$" . php-variable-sigil) | ||
("value" . php-variable-name) | ||
("));\n }\n\n ") | ||
("// " . font-lock-comment-delimiter-face) | ||
("All write operations go through this hook, which has to write to the backing value itself.\n" . font-lock-comment-face) | ||
(" ") | ||
("// " . font-lock-comment-delimiter-face) | ||
("Read access happens normally.\n" . font-lock-comment-face) | ||
(" ") | ||
("public" . php-keyword) | ||
(" ") | ||
("string" . php-class) | ||
(" ") | ||
("$" . php-variable-sigil) | ||
("lastName" . php-variable-name) | ||
(" {\n ") | ||
("set" . php-builtin) | ||
(" {\n ") | ||
("if" . php-keyword) | ||
(" (") | ||
("strlen" . php-function-call-traditional) | ||
("(") | ||
("$" . php-variable-sigil) | ||
("value" . php-variable-name) | ||
(") ") | ||
("<" . php-comparison-op) | ||
(" 2) {\n ") | ||
("throw" . php-keyword) | ||
(" ") | ||
("new" . php-keyword) | ||
(" ") | ||
("\\InvalidArgumentException" . font-lock-type-face) | ||
("(") | ||
("'Too short'" . php-string) | ||
(");\n }\n ") | ||
("$" . php-this-sigil) | ||
("this" . php-this) | ||
("->" . php-object-op) | ||
("lastName" . php-property-name) | ||
(" ") | ||
("=" . php-assignment-op) | ||
(" ") | ||
("$" . php-variable-sigil) | ||
("value" . php-variable-name) | ||
(";\n }\n }\n}\n\n") | ||
("$" . php-variable-sigil) | ||
("p" . php-variable-name) | ||
(" ") | ||
("=" . php-assignment-op) | ||
(" ") | ||
("new" . php-keyword) | ||
(" ") | ||
("Person" . font-lock-type-face) | ||
("();\n\n") | ||
("$" . php-variable-sigil) | ||
("p" . php-variable-name) | ||
("->" . php-object-op) | ||
("firstName" . php-property-name) | ||
(" ") | ||
("=" . php-assignment-op) | ||
(" ") | ||
("'peter'" . php-string) | ||
(";\n") | ||
("print" . php-keyword) | ||
(" ") | ||
("$" . php-variable-sigil) | ||
("p" . php-variable-name) | ||
("->" . php-object-op) | ||
("firstName" . php-property-name) | ||
("; ") | ||
("// " . font-lock-comment-delimiter-face) | ||
("Prints \"Peter\"\n" . font-lock-comment-face) | ||
("$" . php-variable-sigil) | ||
("p" . php-variable-name) | ||
("->" . php-object-op) | ||
("lastName" . php-property-name) | ||
(" ") | ||
("=" . php-assignment-op) | ||
(" ") | ||
("'Peterson'" . php-string) | ||
(";\n") | ||
("print" . php-keyword) | ||
(" ") | ||
("$" . php-variable-sigil) | ||
("p" . php-variable-name) | ||
("->" . php-object-op) | ||
("fullName" . php-property-name) | ||
("; ") | ||
("// " . font-lock-comment-delimiter-face) | ||
("Prints \"Peter Peterson\"\n" . font-lock-comment-face)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters