CREATE TABLE users( id INTEGER PRIMARY KEY, name TEXT NOT NULL, description TEXT NOT NULL ); このテーブルに関して, 「指定された ID のユーザの, 指定されたフィールドのみを 差分更新したい」 という要求があり,それに合わせて以下のように UserRepository クラスを実装した。 class UserRepository { public function update( int $id, ?string $name = null, ?string $description = null, ): void { // 処理内容はダミー $updated = []; if ($name !== null) { $updated['name'] = $name; } if ($descript
![PHP 8.1 において名前付き引数で NULL と引数省略を区別する方法](https://cdn-ak-scissors.b.st-hatena.com/image/square/36cbaf11c33500c078765f8bacc20270214e10bd/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--exoqD7u_--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3APHP%2525208.1%252520%2525E3%252581%2525AB%2525E3%252581%25258A%2525E3%252581%252584%2525E3%252581%2525A6%2525E5%252590%25258D%2525E5%252589%25258D%2525E4%2525BB%252598%2525E3%252581%25258D%2525E5%2525BC%252595%2525E6%252595%2525B0%2525E3%252581%2525A7%252520NULL%252520%2525E3%252581%2525A8%2525E5%2525BC%252595%2525E6%252595%2525B0%2525E7%25259C%252581%2525E7%252595%2525A5%2525E3%252582%252592%2525E5%25258C%2525BA%2525E5%252588%2525A5%2525E3%252581%252599%2525E3%252582%25258B%2525E6%252596%2525B9%2525E6%2525B3%252595%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3Ampyw%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyLzk0ZWM3OGU4NDYuanBlZw%3D%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)