fmt() Helper¶
-
Type Preservation
Pass any data type between components with perfect type safety
-
Zero Configuration
Works automatically with classes, arrays, objects, and primitives
-
Auto Serialization
Automatic encoding and decoding behind the scenes
-
Type Safe
Maintains exact type signatures across component boundaries
New in v2.0.1
Enhanced type preservation for component props
Quick Start¶
<?php
class User {
public function __construct(
public string $name,
public int $age
) {}
}
$user = new User('John Doe', 25);
fmt($user);
// Pass to component - receives exact User instance!
return "<UserProfile>{$user}</UserProfile>";
<?php
function UserProfile(User $children) {
// Type-safe - receives actual User instance
return <<<HTML
<div>
<h2>{$children->name}</h2>
<p>Age: {$children->age}</p>
</div>
HTML;
}
Multiple Arguments¶
<?php
$product = new Product('iPhone', 999.99);
$options = ['badge' => 'New'];
$theme = 'dark';
fmt($product, $options, $theme);
return "<ProductCard theme='{$theme}' options='{$options}'>{$product}</ProductCard>";
What It Does¶
fmt() preserves exact data types when passing props between components:
- ✅ Custom classes remain their original type
- ✅ Arrays, objects, strings, numbers all preserved
- ✅ Works with interfaces, readonly properties, enums
- ✅ Automatic serialization/deserialization
Component Tags Only
Only works with component tag syntax: <Component>{$data}</Component>