Hello Levi,
I thought it was clear.
By static "factory" method I just mean any static method that returns an object.
Don't interpret too much into the term :)

So to clarify, here is an example:

class OtherAttribute {}

class MyAttribute {
  public function __construct(string $name) {..}

  #[Attribute]
  public static function create(string $name): self {
    return new self($name);
  }

  #[Attribute]
  public static function createOther($x): OtherAttribute {
    return new OtherAttribute($x);
  }
}

class SomeValue {
  public static function create() {return new self();}
}

#[MyAttribute::create('hello')]
#[MyAttribute::createOther(SomeValue::create())]
class C {}

// This is the other part, static method calls in regular initializers.
function f($x = SomeValue::create())


Things to observe:
- The classes MyAttribute and OtherAttribute are not marked as
attribute via #[Attribute] annotation. Only the static methods are.
- MyAttribute::create() and MyAttribute::createOther() are allowed to
return any object that they want.

On Mon, 27 Sept 2021 at 18:26, Levi Morrison via internals
<internals@lists.php.net> wrote:
>
> I'm not exactly sure what you are proposing. However, it's always
> worth noting other languages which have something in the feature
> space, and Dart has both named constructors and factory constructors.
> You should start with researching what they do, and what other
> languages may have the same as _language features_, and not as
> patterns e.g. Java has a factory pattern, but it's not part of the
> language (at least not that I last checked, I don't follow Java).
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to