Files
php-question/Question12-Encapsulation/Ex01.php
2026-10-06 12:10:09 +09:00

34 lines
1.9 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* [Ex01 オブジェクト指向 - Studentクラスのアクセサの実装と制御処理の追加]
*
* TODO:
* 1. 新しいファイル "Student.php" を作成し、以下の仕様に従って Student クラスを定義してください。
* - クラス名: Student
* - プロパティ(すべて private とする):
* student_id, student_name, company_name, class_name, mail, password
* - 各プロパティに対して、シンプルなゲッター(getXXX)とセッター(setXXX)を実装してください。
* (例:getStudentId() と setStudentId($id) など)
*
* (下記は1,2,3,4の処理が終わった後の+αの課題です)
*   シンプルな実装ができたら、下記の特定のセッターに対して、追加の制御処理(バリデーション)を実装するようにしてください:
*  a. setStudentId($id) : $id が正の整数であることをチェックし、正しくない場合は 0 をセットする。
*  b. setMail($mail) : $mail が有効なメールアドレスの形式かチェックし、無効な場合は "unknown@example.com" をセットする。
*  c. setPassword($password) : $password の長さが8文字以上であるかチェックし、短い場合は "defaultPass" をセットする。
*
* 2. 本ファイル内で、require_once を使い "Student.php" を読み込んでください。
*
* 3. Student クラスのインスタンスを生成し、以下の値を各セッターで設定してください。
* - student_id: 10001
* - student_name: "リゾーム太郎"
* - company_name: "株式会社リゾーム"
* - class_name: "Z教室"
* - mail: "rhizome@hogehoge.com"
* - password: "1qazxcvb"
*
* 4. 各プロパティの値を、対応するゲッターを使って出力してください。
*
*
*/