@Stellar@mk.absturztau.be @puniko@mk.absturztau.be Just glancing over the codebase the tutorial you used contains a lot of outdated PHP concepts.
There's a lot of cool new syntax that you're missing out that makes life a lot easier.
$array[] = $item instead of array_push($array, $item).
$array = [] instead of $array = array().
if ($variable) instead of if (!empty($variable) (PHP is loose typed, which is a good thing).
Variable names with camelCase instead of snake_case (This is according to modern PSR-12 standards).
In HTML templates use <?= $variable; ?> instead of <?php echo $variable; ?>, it's a really nice shorthand.
You can easily make your code less error prone by adding types to functions return types and parameters: function togglePublishPost(int $postId, string $message): void instead of function togglePublishPost($post_id, $message).
Do not return exception messages to the browser: catch (Exception $e) { return $e->getMessage(); }. This could provide an attacker with sensitive information about your server. Write this to a log file instead.
While not wrong technically I also highly recommend dropping any functional programming patterns in favor of OOP.
And if you really want to build something nice I recommend getting started with a framework such as Laravel.
Embed Notice
HTML Code
Corresponding Notice
- Embed this notice
SuperDicq (superdicq@minidisc.tokyo)'s status on Thursday, 03-Apr-2025 05:32:01 JST SuperDicq