I saw a class in Laravel where "new static()" is being called to create object chaining as opposed to "return $this" which is what i'm familiar with seeing.
Does anyone know why this approach is taken and is there a term for it? file:
vendor\laravel\framework\src\Illuminate\Support\Stringable.php
class Stringable implements JsonSerializable
{
protected $value;
public function __construct($value = '')
{
$this->value = (string) $value;
}
public function camel()
{
return new static(Str::camel($this->value)); // <-- why not "return $this;" instead?
}
}
Trying to understand the approach.