Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Counterpoint (from the same website): https://stitcher.io/blog/evolution-of-a-php-object

PHP 8.2 has this:

``` readonly class BlogData

{

    public function __construct(

        public string $title,

        public State $state,

        public ?DateTimeImmutable $publishedAt = null,

    ) {}
}

```

Whereas in php 5.6, to accomplish the same you need all this:

``` class BlogData { /* @var string / private $title;

    /** @var State */
    private $state;
    
    /** @var \DateTimeImmutable|null */
    private $publishedAt;
   
   /**
    * @param string $title 
    * @param State $state 
    * @param \DateTimeImmutable|null $publishedAt 
    */
    public function __construct(
        $title,
        $state,
        $publishedAt = null
    ) {
        $this->title = $title;
        $this->state = $state;
        $this->publishedAt = $publishedAt;
    }
    
    /**
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;    
    }
    
    /**
     * @return State 
     */
    public function getState() 
    {
        return $this->state;    
    }
    
    /**
     * @return \DateTimeImmutable|null 
     */
    public function getPublishedAt() 
    {
        return $this->publishedAt;    
    }
} ```


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: