3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace MCC\SocialCare\Component\User\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="user") */ class User implements \Serializable { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") * @var int */ protected $id; /** * @ORM\Column(name="first_name", type="string", nullable=true) * @var string */ protected $firstName; /** * @ORM\Column(name="last_name", type="string", nullable=true) * @var string */ protected $lastName; /** * @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"}, fetch="EAGER") * @ORM\JoinTable(name="user_roles") * * @var Role[]|Collection */ protected $roles; /** * @ORM\ManyToMany(targetEntity="Group", inversedBy="users", cascade={"persist"}, fetch="EAGER") * @ORM\JoinTable(name="user_groups") * * @var Group[]|Collection */ protected $groups; /** * @ORM\ManyToMany(targetEntity="MCC\SocialCare\Component\Team\Entity\Team", mappedBy="users") * * @var Team[]|Collection */ protected $teams; /** * @ORM\OneToMany(targetEntity="MCC\SocialCare\Component\Team\Entity\Team", mappedBy="manager") * * @var Team[]|Collection */ protected $managedTeams; /** * The cases in which the user is a key worker on. * * @ORM\OneToMany( * targetEntity="MCC\SocialCare\Component\ServiceUserCase\Entity\ServiceUserCase", * mappedBy="keyWorker" * ) * * @var ServiceUserCase[]|Collection */ protected $keyCases; /** * The cases the user is simply involved with. * * @ORM\ManyToMany(targetEntity="MCC\SocialCare\Component\ServiceUserCase\Entity\ServiceUserCase", mappedBy="users") * * @var Team[]|Collection */ protected $cases; /** * The users notifications. * * @ORM\OneToMany( * targetEntity="MCC\SocialCare\Component\Notification\Entity\NotificationMessage", * mappedBy="recipient", * cascade={"persist"} * ) * * @var NotificationMessage[]|Collection */ protected $notifications; public function __construct() { parent::__construct(); $this->roles = new ArrayCollection(); $this->groups = new ArrayCollection(); $this->teams = new ArrayCollection(); $this->managedTeams = new ArrayCollection(); $this->keyCases = new ArrayCollection(); $this->cases = new ArrayCollection(); $this->notifications = new ArrayCollection(); } /** * @return string */ public function getFullName() { return $this->firstName.' '.$this->lastName; } /** * {@inheritdoc} */ public function setFirstName($firstName) { $this->firstName = $firstName; return $this; } /** * {@inheritdoc} */ public function getFirstName() { return $this->firstName; } /** * {@inheritdoc} */ public function setLastName($lastName) { $this->lastName = $lastName; return $this; } /** * {@inheritdoc} */ public function getLastName() { return $this->lastName; } /** * @param string|Role $role * @return User */ public function addRole($role) { if (!$role instanceof Role) { $role = (new Role)->setRole($role); } if (!$this->hasRole($role)) { $this->roles->add($role); } return $this; } /** * @param string|Role $role * @return User */ public function removeRole($role) { if ($role instanceof Role) { $this->roles->removeElement($role); return $this; } foreach ($this->roles as $r) { if ($r->getRole() === $role) { $this->roles->removeElement($r); } } return $this; } /** * @param string|Role $role * @return bool */ public function hasRole($role) { if ($role instanceof Role) { $role = $role->getRole(); } return $this->roles->exists(function ($key, Role $element) use ($role) { return $role === $element->getRole(); }); } /** * @return Role[] */ public function getRoles() { $roles = $this->roles->toArray(); foreach ($this->getGroups() as $group) { $roles = array_merge($roles, $group->getRoles()); } return $roles; } /** * @param GroupInterface $group * @return User */ public function addGroup(GroupInterface $group) { if (!$this->hasGroup($group)) { $this->groups[] = $group; } return $this; } /** * @param GroupInterface $group * @return User */ public function removeGroup(GroupInterface $group) { $this->groups->removeElement($group); return $this; } /** * @param string|GroupInterface $group * @return bool */ public function hasGroup($group) { if ($group instanceof GroupInterface) { return $this->groups->contains($group); } return $this->groups->exists(function ($key, GroupInterface $element) use ($group) { return $group === $element->getName(); }); } /** * @return Collection|Group[] */ public function getGroups() { return $this->groups; } /** * @param Team $team * @return $this */ public function addTeam(Team $team) { if (!$this->hasTeam($team)) { $this->teams->add($team); $team->addUser($this); } return $this; } /** * @param Team $team * @return $this */ public function removeTeam(Team $team) { if ($this->hasTeam($team)) { $this->teams->removeElement($team); $team->removeUser($this); } return $this; } /** * @param Team $team * @return bool */ public function hasTeam(Team $team) { return $this->teams->contains($team); } /** * @return Collection|Team[] */ public function getTeams() { return $this->teams; } /** * @param Team $team * @return $this */ public function addManagedTeam(Team $team) { if (!$this->hasManagedTeam($team)) { $this->managedTeams->add($team); $team->setManager($this); } return $this; } /** * @param Team $team * @return $this */ public function removeManagedTeam(Team $team) { if ($this->hasManagedTeam($team)) { $this->managedTeams->removeElement($team); $team->setManager(null); } return $this; } /** * @param Team $team * @return bool */ public function hasManagedTeam(Team $team) { return $this->managedTeams->contains($team); } /** * @return Collection|Team[] */ public function getManagedTeams() { return $this->managedTeams; } /** * @param ServiceUserCase $keyCase * @return $this */ public function addKeyCase(ServiceUserCase $keyCase) { if (!$this->hasKeyCase($keyCase)) { $this->keyCases->add($keyCase); $keyCase->setKeyWorker($this); } return $this; } /** * @param ServiceUserCase $keyCase * @return $this */ public function removeKeyCase(ServiceUserCase $keyCase) { if ($this->hasKeyCase($keyCase)) { $this->keyCases->removeElement($keyCase); $keyCase->setKeyWorker(null); } return $this; } /** * @param ServiceUserCase $keyCase * @return bool */ public function hasKeyCase(ServiceUserCase $keyCase) { return $this->keyCases->contains($keyCase); } /** * @return Collection|ServiceUserCase[] */ public function getKeyCases() { return $this->keyCases; } /** * @param ServiceUserCase $case * @return $this */ public function addCase(ServiceUserCase $case) { if (!$this->hasCase($case)) { $this->cases->add($case); $case->addUser($this); } return $this; } /** * @param ServiceUserCase $case * @return $this */ public function removeCase(ServiceUserCase $case) { if ($this->hasCase($case)) { $this->cases->removeElement($case); $case->removeUser($this); } return $this; } /** * @param ServiceUserCase $case * @return bool */ public function hasCase(ServiceUserCase $case) { return $this->cases->contains($case); } /** * @return Collection|ServiceUserCase[] */ public function getCases() { return $this->cases; } /** * @param NotificationMessage $message * @return $this */ public function addNotification(NotificationMessage $message) { if (!$this->hasNotification($message)) { $message->setRecipient($this); $this->notifications->add($message); } return $this; } /** * @param NotificationMessage $message * @return $this */ public function removeNotfication(NotificationMessage $message) { if ($this->hasNotification($message)) { $this->notifications->removeElement($message); $message->setRecipient(null); } return $this; } /** * @param NotificationMessage $message * @return bool */ public function hasNotification(NotificationMessage $message) { return $this->notifications->contains($message); } /** * @return Collection|NotificationMessage[] */ public function getNotifications() { return $this->notifications; } /** * Get unread notification messages * * @return Collection|NotificationMessage[] */ public function getUnreadNotifications() { $criteria = Criteria::create() ->where(Criteria::expr()->eq('read', false)); return $this->notifications->matching($criteria); } /** * Serializes the user. * * The serialized data have to contain the fields used by the equals method and the username. * * @return string */ public function serialize() { return serialize(array( $this->password, $this->salt, $this->usernameCanonical, $this->username, $this->expired, $this->locked, $this->credentialsExpired, $this->enabled, $this->id, )); } /** * Unserializes the user. * * @param string $serialized */ public function unserialize($serialized) { $data = unserialize($serialized); // add a few extra elements in the array to ensure that we have enough keys when unserializing // older data which does not include all properties. $data = array_merge($data, array_fill(0, 2, null)); list( $this->password, $this->salt, $this->usernameCanonical, $this->username, $this->expired, $this->locked, $this->credentialsExpired, $this->enabled, $this->id ) = $data; } } var_dump( unserialize('a:4:{i:0;C:41:"MCC\SocialCare\Component\User\Entity\User":206:{a:9:{i:0;s:60:"$2y$15$2m55uqgw1dc0488k0k44kuj5jlsY5zHjNX/WlJ75iKn1NgPX6rcMS";i:1;s:31:"2m55uqgw1dc0488k0k44k0co8wk8csw";i:2;s:10:"superadmin";i:3;s:10:"superadmin";i:4;b:0;i:5;b:0;i:6;b:0;i:7;b:1;i:8;i:12;}}i:1;b:1;i:2;a:2:{i:0;C:41:"MCC\SocialCare\Component\User\Entity\Role":42:{a:2:{i:0;i:3;i:1;s:16:"ROLE_SUPER_ADMIN";}}i:1;r:16;}i:3;a:0:{}}') );
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Cannot use "parent" when current class scope has no parent in /in/9RgRN on line 102
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Cannot use "parent" when current class scope has no parent in /in/9RgRN on line 102 Warning: Class __PHP_Incomplete_Class has no unserializer in /in/9RgRN on line 556 Notice: unserialize(): Error at offset 396 of 408 bytes in /in/9RgRN on line 556 bool(false)
Output for 7.3.32 - 7.3.33
Warning: Class __PHP_Incomplete_Class has no unserializer in /in/9RgRN on line 556 bool(false)
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.3 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
Warning: Class __PHP_Incomplete_Class has no unserializer in /in/9RgRN on line 556 Notice: unserialize(): Error at offset 396 of 408 bytes in /in/9RgRN on line 556 bool(false)
Output for 7.0.0 - 7.0.2
Warning: Class __PHP_Incomplete_Class has no unserializer in /in/9RgRN on line 556 array(4) { [0]=> object(MCC\SocialCare\Component\User\Entity\User)#1 (18) { ["id":protected]=> int(12) ["firstName":protected]=> NULL ["lastName":protected]=> NULL ["roles":protected]=> NULL ["groups":protected]=> NULL ["teams":protected]=> NULL ["managedTeams":protected]=> NULL ["keyCases":protected]=> NULL ["cases":protected]=> NULL ["notifications":protected]=> NULL ["password"]=> string(60) "$2y$15$2m55uqgw1dc0488k0k44kuj5jlsY5zHjNX/WlJ75iKn1NgPX6rcMS" ["salt"]=> string(31) "2m55uqgw1dc0488k0k44k0co8wk8csw" ["usernameCanonical"]=> string(10) "superadmin" ["username"]=> string(10) "superadmin" ["expired"]=> bool(false) ["locked"]=> bool(false) ["credentialsExpired"]=> bool(false) ["enabled"]=> bool(true) } [1]=> bool(true) [2]=> array(1) { [0]=> object(__PHP_Incomplete_Class)#2 (1) { ["__PHP_Incomplete_Class_Name"]=> string(41) "MCC\SocialCare\Component\User\Entity\Role" } } [3]=> array(0) { } }
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/9RgRN on line 163
Process exited with code 255.

preferences:
217.97 ms | 401 KiB | 402 Q