88 * ```
99 * echo (new Pipe('NOW')) // wrap initial value
1010 * (strtolower(...)) // map through strtolower() => 'now'
11- * ->new(DateTimeImmutable::class, Pipe::PLACEHOLDER, DateTimeZone:: UTC) // create class
11+ * ->new(DateTimeImmutable::class, Pipe::PLACEHOLDER, new DateTimeZone(' UTC') ) // create class
1212 * ->format("Y_m_d") // calls 'format' method => '2025_01_01' (that was 'now' not long ago...)
1313 * (str_replace(...), '_', '-') // => '2025-01-01'
1414 * (explode(...), '-', Pipe::PLACEHOLDER, 2) // => ['2025', '01-01']
@@ -63,7 +63,7 @@ public function new(string $class, mixed ... $args): self
6363
6464 /**
6565 * Returns the class field or array element with key `$key`.
66- * @param string|int $key the key. when it is an integer, array access is used automatically.
66+ * @param string|int $key the key. When it is an integer, array access is used automatically.
6767 * @param bool $array_access whether to use array access
6868 * @since 1.0
6969 */
@@ -73,6 +73,22 @@ public function get(string|int $key, bool $array_access = false): self
7373 return $ this ;
7474 }
7575
76+ /**
77+ * Sets the class field or array element with key `$key` to `$value`.
78+ * @param string|int $key the key. When it is an integer, array access is used automatically.
79+ * @param mixed $value the value to be set for the `$key`.
80+ * @param bool $array_access whether to use array access
81+ * @since 1.2
82+ */
83+ public function set (string |int $ key , mixed $ value , bool $ array_access = false ): self
84+ {
85+ if ($ array_access || is_int ($ key ))
86+ $ this ->value [$ key ] = $ value ;
87+ else
88+ $ this ->value ->{$ key } = $ value ;
89+ return $ this ;
90+ }
91+
7692 public function __toString (): string
7793 {
7894 return "$ this ->value " ;
0 commit comments