PHP code example of chiroruxx / php-scope-function
1. Go to this page and download the library: Download chiroruxx/php-scope-function library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chiroruxx / php-scope-function example snippets
class User
{
use \Chiroruxx\ScopeFunction\ScopeFunction;
// ...
}
$user = User::find($id);
$json = $user?->let(function (User $it): string {
$formatter = new UserFormatter();
return $formatter->formatToJson($it);
});
return $json ?? '';
$user->also(function (User $it): void {
$it->created_at = new DateTime();
$it->updated_at = new DateTime();
})
->save();