Skip to content

Commit c223222

Browse files
committed
feat: add php 8.1 enums examples
1 parent ab595c5 commit c223222

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

php8.1-news/docker.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
example=$(ls src | fzf)
2+
3+
docker run -it -v `pwd`:`pwd` -w `pwd` phpdaily/php:8.1-dev php "src/$example" 2>/dev/null

php8.1-news/src/1-basic_enum.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
enum Editor: string {
4+
case VSCode = 'Visual Studio Code';
5+
case Idea = 'Intellij Idea';
6+
case Sublime = 'Sublime Text';
7+
}
8+
9+
function is_good(Editor $editor) {
10+
$yesMessage = 'Yeah, %s is good';
11+
$nopeMessage = 'Nope, %s is not good';
12+
13+
return sprintf(rand(0,1) == 1 ? $yesMessage : $nopeMessage, $editor->value);
14+
}
15+
16+
17+
echo is_good(Editor::VSCode) . "\n";
18+
echo is_good(Editor::Idea) . "\n";
19+
echo is_good(Editor::Sublime) . "\n";

php8.1-news/src/2-explore_enum.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
enum Editor: string {
4+
case VSCode = 'Visual Studio Code';
5+
case Idea = 'Intellij Idea';
6+
case Sublime = 'Sublime Text';
7+
8+
public function creator(): string {
9+
return match ($this) {
10+
Editor::VSCode => 'Microsoft',
11+
Editor::Idea => 'JetBrains',
12+
Editor::Sublime => 'Someone',
13+
};
14+
}
15+
}
16+
17+
echo Editor::Idea->creator();

0 commit comments

Comments
 (0)