PHP 7.4에서 내가 좋아하는 것
어쩌면 누군가 나에게 미쳤다고 말할 수 있지만 나는 강력한 형식의 언어를 정말 좋아합니다. 그리고 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에 대해 어떻게 생각하시나요? 약한 유형의 언어 또는 강력한 유형의 언어를 더 좋아합니까?
Reference
이 문제에 관하여(PHP 7.4에서 내가 좋아하는 것), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/maymeow/what-i-like-on-php-7-4-4c9i텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)