PHP 7.4에서 내가 좋아하는 것

5383 단어 phpdiscuss
좋아, 내가 좋아하는 것이 더 있지만 이것은 나를 위한 가장 큰 도전입니다.

어쩌면 누군가 나에게 미쳤다고 말할 수 있지만 나는 강력한 형식의 언어를 정말 좋아합니다. 그리고 7.4 릴리스에서는 PHP가 더 가깝습니다. (그리고 더 많은 것이 8.0에 올 것입니다) .

이제 내 모델 클래스는 다음과 같이 보일 수 있습니다.

class UserIndexViewModel
{
    protected int $id;
    protected string $email;
    protected int $groupId;
    protected string $groupName;
    protected bool $isActive;
    protected bool $isAdmin;
    protected FrozenTime $created;
    protected FrozenTime $modified;

    /**
     * UserIndexViewModel constructor.
     * @param int $id
     * @param string $email
     * @param int $groupId
     * @param string $groupName
     * @param bool $isActive
     * @param bool $isAdmin
     * @param FrozenTime $created
     * @param FrozenTime $modified
     */
    private function __construct(int $id, string $email, int $groupId, string $groupName, bool $isActive, bool $isAdmin, FrozenTime $created, FrozenTime $modified)
    {
        $this->id = $id;
        $this->email = $email;
        $this->groupId = $groupId;
        $this->groupName = $groupName;
        $this->isActive = $isActive;
        $this->isAdmin = $isAdmin;
        $this->created = $created;
        $this->modified = $modified;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }
// ...
}


내가 지금 놓치고 있는 생각 중 하나는 객체의 배열입니다. 7.4에서는 정의할 수 없습니다. 단순히 배열을 정의하지만 여기에는 해결 방법이 있으며 문서 블록에서 정의할 수 있습니다.

   /**
     * Returns populated array f ViewModel
     *
     * @param \Cake\Datasource\ResultSetInterface|\Iam\Model\Entity\User[] $data
     * @param IdentityInterface $identity
     * @return array|\Iam\ViewModel\UserIndexViewModel[]
     */
    public static function prepare(ResultSetInterface $data, IdentityInterface $identity) : array


PHP 8.0(RC 단계에 있음)은 Union 유형을 가져올 것이므로 변경될 수 있습니다.

지금 PHP에 대해 어떻게 생각하시나요? 약한 유형의 언어 또는 강력한 유형의 언어를 더 좋아합니까?

좋은 웹페이지 즐겨찾기