Docs UI Examples Benchmarks Showcase

Coming from SwiftUI

A guide for people and coding agents who know SwiftUI and are about to write a myphp view. myphp's views are SwiftUI's: the same names, argument labels and order, in PHP syntax. Left is SwiftUI, right is myphp; every PHP block runs headless in tests/docs_examples_test.php. In the blocks, $app is the state and $view what a view file returns. docs/mobile.md covers what a phone adds; docs/upstream-deviations.md lists where myphp differs from the Go framework it ports.

The shape of an app

struct Counter: View {
    @State var n = 0
    var body: some View {
        VStack(spacing: 12) {
            Text("\(n)").font(.largeTitle).bold()
            Button("Increment") { n += 1 }
        }
    }
}
$app = new class { public int $n = 0; };
$view = fn() => VStack(spacing: 12)(
    Text(verbatim: (string)$app->n)->font(Font::largeTitle)->bold(),
    Button('Increment', action: fn() => $app->n++),
);

In an app the state is a class of its own, and the view a file, view.php, that returns that closure with $this for $app (Content::file(__DIR__ . '/view.php', $app)): saved, it hot reloads with the state kept, as SwiftUI's previews and Flutter's hot reload do (view files). The view runs for every frame, as SwiftUI's body runs for every change: it reads the state and returns views; actions change the state.

Where PHP differs (the only differences)

The rule: every SwiftUI view, modifier and pattern is written as SwiftUI writes it, in PHP syntax: the same names, the same argument labels, the same order. A difference needs a reason in PHP itself, listed here. A myphp view SwiftUI has no counterpart of (a terminal, a video player, a rating…) takes a SwiftUI-shaped name and its arguments as SwiftUI would name them.

SwiftUImyphpWhy
VStack(spacing: 12) { … }VStack(spacing: 12)( … )No trailing closures; the second parentheses are the braces
Children on lines, no separatorsChildren separated by commasA PHP argument list
if cond { Text("a") } in a builder$cond ? Text('a') : nullNo result builders: null is no view, an array is several
ForEach(items, id: \.id) { … }Each($items, id: 'id')(fn(array $item) => …)foreach is a PHP keyword, any case
List { … }ListView( … )list is a PHP keyword
Link("Docs", destination: url)WebLink('Docs', destination: $url)PHP has a built-in link()
@State var n = 0 in the viewA property of the state classA view is a closure, rebuilt every frame: state lives in the state object
$bindingThe property itself: Toggle('Wi-Fi', isOn: $app->wifi)PHP passes by reference
.font(.largeTitle)->font(Font::largeTitle)No implicit member expressions: the enum is named
"\(n)""{$app->n}"PHP's interpolation
struct Row: View$row = fn(Todo $t) => … in the view fileA class cannot be loaded twice: a closure hot reloads

VStack, Text, Button… are global functions and Font, Color, Alignment… global enums (src/UI/Declarative/functions.php, loaded with the framework): no use line, as SwiftUI needs no import beyond SwiftUI.

State and data flow

SwiftUImyphp
@State var on = false$on = State(false) or a PHP 8.4 hooked property (Observer::get / Observer::set), or public bool $on = false;
@Binding var on: Bool, passed as $onThe property or State itself: Toggle('Wi-Fi', isOn: $app->on); Binding::of($app, 'on') or Binding(get:, set:)
@StateObject, @ObservablePHP 8.4 Property Hooks (Observer::get / Observer::set) + fn() => … child closures (or Computed(fn() => …)) for fine-grained retained subtrees
@Environment(\.colorScheme)->preferredColorScheme() to set it; the theme follows the system
@FocusState->focused($app->editing), ->defaultFocus()
onChange(of: value) { }->onChange(of: $app->value, action: fn() => …)
@AppStorageA file under App::path(PathName::UserData), read when the state is made, written from its methods
$app = new class { public int $count = 0; public bool $wifi = true; public float $volume = 0.5; public int $changes = 0; };
$view = fn() => Form()(
    fn() => Text(verbatim: "Count: {$app->count}"),
    Toggle('Wi-Fi', isOn: $app->wifi),
    $app->wifi ? Slider(value: $app->volume, in: [0, 1])->onChange(of: $app->volume, action: fn() => $app->changes++) : null,
);

Layout

SwiftUImyphp
VStack(alignment: .leading, spacing: 8) { }VStack(alignment: HorizontalAlignment::leading, spacing: 8)( … )
HStack, ZStack(alignment:)HStack(alignment: VerticalAlignment::top)( … ), ZStack(alignment: Alignment::topTrailing)( … )
Spacer(), Divider()Spacer(), Divider()
.frame(width: 200, height: 44)->frame(width: 200, height: 44)
.frame(maxWidth: .infinity, alignment: .leading)->frame(maxWidth: INF, alignment: Alignment::leading)
.padding(), .padding(.horizontal, 12)->padding(), ->padding(Edge::horizontal, 12)
.offset(x: 10)->offset(x: 10)
.overlay(alignment: .topTrailing) { Badge() }->overlay(Text('3'), alignment: Alignment::topTrailing)
GeometryReader { proxy in }GeometryReader(fn(GeometryProxy $proxy) => …)
Grid { GridRow { } }, .gridCellColumns(2)Grid()(GridRow()( … )), ->gridCellColumns(2)
LazyVGrid(columns:), LazyHGrid(rows:)LazyVGrid(columns: [GridItem::adaptive(minimum: 120), GridItem::flexible(), GridItem::fixed(80)])( … ), LazyHGrid(rows: […])( … )
LazyVStack, LazyHStackLazyVStack()( … ), LazyHStack()( … )
ScrollView { }, EmptyView()ScrollView()( … ) (ScrollViewReader to scroll to an id), EmptyView()
$view = fn() => HStack(spacing: 12)(
    Text('Title')->bold(),
    Spacer(),
    Button('Edit', action: fn() => null),
)->padding()->frame(maxWidth: INF);

Text and fonts

SwiftUImyphp
Text("Hi"), Text(verbatim:)Text('Hi') (looked up in the app's strings), Text(verbatim: $s)
.font(.title), .font(.caption)->font(Font::title), ->font(Font::caption): the text styles, at the platform's size, scaled with the system's text size; ->font(Font::system(size: 28))
.bold(), .fontWeight(.semibold)->bold(), ->fontWeight(Weight::semibold)
.italic(), .underline(), .strikethrough(), .monospaced()the same names
.foregroundStyle(.secondary)->foregroundStyle(Color::secondary)
.multilineTextAlignment(.center), .lineLimit(2)->multilineTextAlignment(TextAlignment::center), ->lineLimit(2)
.textSelection(.enabled)->textSelection(TextSelectability::enabled)
MarkdownMarkdown($text) (and streaming: true while it arrives)
Label("Save", systemImage: "square.and.arrow.down")the same: an SF Symbol on Apple platforms, the GTK theme's icon on Linux, a Material Symbol on Android
$view = fn() => VStack(alignment: HorizontalAlignment::leading, spacing: 4)(
    Text('Settings')->font(Font::largeTitle)->bold(),
    Text('12 files, 3.4 MB')->foregroundStyle(Color::secondary),
    Text('A long description that wraps and is cut after two lines.')->lineLimit(2),
);

Colors, backgrounds and materials

SwiftUImyphp
Color.accentColor, .primary, .secondaryColor::accentColor, Color::primary, Color::secondary
Color(.systemBackground), Color(.secondarySystemBackground)Color::systemBackground, Color::secondarySystemBackground (and the grouped ones, ::label, ::separator, ::systemGray…)
.red, .orange, .greenColor::red, Color::orange, Color::green
A color of the app's ownColor::rgb(0x336699)
.background(.blue), .background { … }->background(Color::blue), ->background($view)
LinearGradient, RadialGradient, AngularGradientLinearGradient(colors: [Color::blue, Color::purple], startPoint: UnitPoint::topLeading, endPoint: UnitPoint::bottomTrailing), RadialGradient(colors: [...]), AngularGradient(colors: [...])
.glassEffect(), .background(.regularMaterial)->glassEffect($material); a window's vibrancy: for the window's material
.cornerRadius(12), .clipShape(RoundedRectangle(cornerRadius: 12))the same
.border(.gray), .shadow(radius: 8, y: 4), .opacity(0.5)->border(Color::separator), ->shadow(radius: 8, y: 4), ->opacity(0.5)
preferredColorScheme(.dark)the same: ->preferredColorScheme(ColorScheme::dark), or App::setColorScheme(true) (null follows the system)
dynamicTypeSize(.xxLarge)the same, or App::setTextScale(DynamicTypeSize::xxLarge->scale())
$view = fn() => VStack(alignment: HorizontalAlignment::leading, spacing: 8)(
    Text('Card')->bold(),
    Text('Follows light and dark mode')->foregroundStyle(Color::secondary),
)->padding()->background(Color::secondarySystemBackground)->cornerRadius(12);

The named colors follow the system's appearance, accent and contrast (see Styling); take a literal only for data, a chart's series or a user's tag.

Controls

SwiftUImyphp
Button("Save") { save() }Button('Save', action: fn() => $app->save())
Button("Copy", systemImage: "doc.on.doc") { }Button('Copy', action: …, systemImage: 'doc.on.doc'): a Label of the title and the symbol; in a phone's context menu the item's icon
Button(role: .destructive), .buttonStyle(.borderedProminent)role: ButtonRole::destructive, ->buttonStyle(ButtonStyle::borderedProminent) (::bordered, ::borderless, ::plain)
.disabled(busy), .keyboardShortcut("s")->disabled($busy), ->keyboardShortcut('s'); ->keyboardShortcut(KeyEquivalent::return, modifiers: [])
Toggle("Wi-Fi", isOn: $on)Toggle('Wi-Fi', isOn: $app->on): a switch on a phone, a checkbox on a Mac; ->toggleStyle(ToggleStyle::switch)
Slider(value: $v, in: 0...1)Slider(value: $app->v, in: [0, 1])
Stepper("Copies", value: $n, in: 1...10)Stepper('Copies', value: $app->n, in: [1, 10])
Picker("Plan", selection: $plan) { Text("Free").tag(0) }Picker('Plan', selection: $app->plan)(Text('Free')->tag(0), …), ->pickerStyle(PickerStyle::segmented) (::menu, ::radioGroup, ::inline)
TextField("Name", text: $name), .onSubmit { }TextField('Name', text: $app->name)->onSubmit(fn() => …); prompt:, axis: Axis::vertical
SecureField, TextEditor(text:)SecureField('Password', text: $app->password), TextEditor(text: $app->notes)
DatePicker, ColorPickerDatePicker('Due', selection: $app->due), ColorPicker('Tint', selection: $app->rgb)
ProgressView(), ProgressView(value:), Gaugethe same
Link("Site", destination:)WebLink('Site', destination: 'https://…')
Menu("Sort") { Button("Name") { } }Menu('Sort')(Button('Name', action: …), …)
.contextMenu { }->contextMenu(Button(…), Divider(), …): a right click on a Mac, a long press on a phone
Image(systemName:), Image("asset")Image(systemName: 'gearshape'), Image(file: $path), Image($svg) (->resizable(), ->scaledToFit(), ->scaledToFill(), ->aspectRatio(ContentMode::fit))
AsyncImage(url:)AsyncImage($url, content: fn(ImageView $img) => $img->resizable(), placeholder: fn() => ProgressView())
PhotosPicker, ShareLink, .fileImporterPhotosPicker('Select Photo', selection: $app->photo), ShareLink($url, title: 'Share'), ->fileImporter(isPresented: $app->importing, onCompletion: fn(array $files) => …)
ContentUnavailableViewContentUnavailableView('No Mail', systemImage: 'tray', description: '…'), ContentUnavailableView::search($query)
.help("tip"), .accessibilityLabel("Close")the same names
Form { Section("Account") { LabeledContent("Version", value: "1.0") } }Form()(Section('Account')(LabeledContent('Version', '1.0')))
$app = new class { public string $name = ''; public int $plan = 0; public bool $news = false; };
$view = fn() => Form()(
    Section('Account')(
        TextField('Name', text: $app->name, prompt: 'Your name'),
        Picker('Plan', selection: $app->plan)(Text('Free')->tag(0), Text('Pro')->tag(1))->pickerStyle(PickerStyle::segmented),
        Toggle('Send me news', isOn: $app->news),
    ),
);

myphp's own controls AppKit has and SwiftUI has not, SwiftUI-shaped: ComboBox(title, text:, items:), TokenField(title, tokens:, suggestions:), Rating(title, value:), RangeSlider(lower:, upper:, in:), Breadcrumbs(path, selection:), Avatar(name), SearchField(text:), NumberField(title, value:, in:), DecimalField(title, value:, in:, step:), EditableText(text:); and the views of what the framework does: VideoPlayer, WebView, TerminalView, CodeEditor, DiffView, Markdown, SpriteView.

Lists and collections

SwiftUImyphp
List(items) { Row($0) }ListView($items, id: 'id')(fn(array $item, int $i) => …): only the rows in view are built, for millions of rows
List(selection: $chosen)ListView($items, id: 'id', selection: $app->chosen)
ForEach(items, id: \.id) { }Each($items, id: 'id')(fn(array $item) => …)
.swipeActions { Button(role: .destructive) }->swipeActions(Button('Delete', role: ButtonRole::destructive, action: …)) on a row: a full swipe performs the first
.onMove->onMove(fn(array $from, int $to) => …) on the list
Section("Today") { }, .listStyle(.plain)Section('Today')( … ), ->listStyle(ListStyle::plain)
.refreshable { await load() }->refreshable(fn() => $app->reload())
.searchable(text:), .searchScopes->searchable($app->query), ->searchScopes($app->scope, Text('All')->tag('all'), …)
Table(rows) { TableColumn("Name", value: \.name) }Table($rows, id: 'id')(TableColumn('Name', value: 'name'), …)
DisclosureGroup, OutlineGroupDisclosureGroup('More', isExpanded: $app->open)( … ), nested for an outline
LazyVGrid of photosLazyVGrid(columns: [GridItem::adaptive(minimum: 140)])(Each($photos)(…))
$app = new class {
    public array $files;
    public function __construct() { $this->files = array_map(fn($i) => ['id' => $i, 'name' => "file-$i.txt"], range(1, 10_000)); }
};
$view = fn() => ListView($app->files, id: 'id')(fn(array $f) => HStack()(
    Text(verbatim: $f['name']),
    Spacer(),
    Text('2 KB')->foregroundStyle(Color::secondary),
));
SwiftUImyphp
NavigationStack(path: $path) { root }NavigationStack(path: $app->path)( root ), $app->path a Router
.navigationDestination(for:) { NoteView(id: $0) }->navigationDestination(for: '/notes/{id}', destination: __DIR__ . '/pages/note.php'), the file returning fn(int $id) => …; {id} comes by name, typed
NavigationLink("Note", value: note)NavigationLink('Note', value: "/notes/$id"); $app->path->push(…) from an action
dismiss(), the back button$app->path->back(); the bar's back button and the edge swipe are built in
.navigationTitle("Notes"), .toolbar { }the same: ->navigationTitle('Notes'), ->toolbar(Button(…), …)
.navigationBarTitleDisplayMode(.large)->navigationBarTitleDisplayMode(TitleDisplayMode::large)
NavigationSplitView { sidebar } detail: { }NavigationSplitView(ListView(…), $detail), for a sidebar of the app's data
TabView { Tab("A", systemImage:, value:) { } }TabView(selection: $app->tab)(Tab('A', systemImage: 'house', value: 'a')( … ), …); ->tabViewStyle(TabViewStyle::sidebarAdaptable) for every screen; ->tabBarMinimizeBehavior(TabBarMinimizeBehavior::onScrollDown)
Tab(value:role: .search), role: .prominentTab(value: 'search', role: TabRole::search): titled Search, in the bar with the others (iOS 27's); TabRole::prominent apart at the bar's end
$app = new class {
    public Router $path; public array $notes = [42 => 'Groceries', 7 => 'Ideas'];
    public function __construct() { $this->path = new Router('/'); }
};
$view = fn() => NavigationStack(path: $app->path)(
    ListView()(Each($app->notes)(fn(string $title, int $id) => NavigationLink($title, value: "/notes/$id")))->navigationTitle('Notes'),
)->navigationDestination(for: '/notes/{id}', destination: fn(int $id) => Text($app->notes[$id] ?? '')->navigationTitle('Note'));

Sheets, alerts, popovers and menus

A presentation is driven by an isPresented binding, as SwiftUI's: a property the control sets back to false when the user dismisses it.

SwiftUImyphp
.sheet(isPresented: $open) { }->sheet(isPresented: $app->open, content: fn() => …): a dialog on the desktop, a sheet from the bottom on a phone, a page sheet on an iPad
.presentationDetents([.medium, .large])the same on the sheet's content: [PresentationDetent::medium(), PresentationDetent::large()]
.alert("Title", isPresented:) { Button("OK") {} } message: { }->alert('Title', isPresented: $app->asking, actions: [Button(…), …], message: '…')
.confirmationDialog->confirmationDialog('Title', isPresented: $app->asking, actions: [Button(…), Button('Cancel', role: ButtonRole::cancel)])
.popover(isPresented:)->popover(isPresented: $app->open, content: fn() => …)
A toast (no SwiftUI equivalent)->toast($app->message): shows while the message is set
$app = new class { public bool $asking = false; public int $deleted = 0; };
$view = fn() => Button('Delete…', role: ButtonRole::destructive, action: fn() => $app->asking = true)
    ->alert('Delete the note?', isPresented: $app->asking, actions: [
        Button('Delete', role: ButtonRole::destructive, action: fn() => $app->deleted++),
        Button('Cancel', role: ButtonRole::cancel),
    ], message: 'This cannot be undone.');

Animation

SwiftUImyphp
withAnimation { open.toggle() }withAnimation(Animation::snappy(), fn() => $app->open = !$app->open)
.animation(.spring, value: x)->animation(Animation::smooth(), value: $app->x)
.spring(duration: 0.5, bounce: 0.2)new Animation(spring: new SpringOptions(duration: 0.5, bounce: 0.2))
.smooth, .snappy, .bouncyAnimation::smooth(), ::snappy(), ::bouncy()
.transition(.opacity), .matchedGeometryEffect->transition(AnyTransition::opacity()), ->matchedGeometryEffect(id: 'card', in: 'ns')
.scaleEffect, .rotationEffect, .offsetthe same names
TimelineView(.animation), .keyframeAnimatorTimelineView()(fn(TimelineViewContext $context) => …), KeyframeAnimator(…)
Reduce MotionHonored by every built-in motion
.sensoryFeedback(.success, trigger: saved)Haptics::success() in the action that saved; Haptics::impact('light'), ::selection()
$app = new class { public bool $open = false; };
$view = fn() => VStack(spacing: 12)(
    Button('Toggle', action: fn() => $app->open = !$app->open),
    RoundedRectangle(cornerRadius: 12)->fill(Color::accentColor)->frame(width: 120, height: 80)
        ->offset(x: $app->open ? 100 : 0)->animation(Animation::snappy(), value: $app->open),
);

Lifecycle, time and async

SwiftUImyphp
.onAppear { }, .onDisappear { }the same
.task { await load() }->task(fn() => $app->load()): a fiber, started as the view appears; inside it Http::get() waits without stopping the window
Timer.publish, TimelineView(.periodic)TimelineView()(fn(TimelineViewContext $context) => …)
@MainActorEverything already is: PHP runs the app on one thread. What waits goes in a fiber (App::go()), heavy CPU work in a child process (see app.md)
URLSession.shared.data(from:), URLRequest, JSONDecoder[$data, $resp] = URLSession::shared()->data(from: $url) (or for: new URLRequest($url, 'POST', body: [...])), URLSession::shared()->json(from: $url), URLSession::shared()->decode(User::class, from: $url), upload(), download(); or Http::get(), Http::post(), Http::postJson(), Http::put(), Http::patch(), Http::delete()
scenePhaseApp::onActivate(), the window's events (see The application)

<!-- no-test -->

$app = new class {
    public array $items = []; public bool $loading = false;
    public function load(): void { $this->loading = true; $this->items = Http::get('https://example.com/items')->json(); $this->loading = false; }
};
$view = fn() => VStack()(
    $app->loading ? ProgressView() : ListView($app->items)(fn(string $item) => Text(verbatim: $item)),
)->task(fn() => $app->load());

Beyond the views: 3D scenes, games & native OS interop (ffigen / jnigen)

  • 2D Canvas & Custom Widgets: Canvas(fn(GraphicsContext $g, CGSize $size) => …) draws 2D vector graphics, as SwiftUI's; Representable(fn(Context $c) => …) wraps a custom engine node inside a view, as NSViewRepresentable / UIViewRepresentable (see Custom widgets).
  • 3D Scenes (SceneView) & 2D/3D Games (SpriteView): SceneView($this->scene, orbitControls: true, onUpdate: …, onPick: …) embeds a 5-platform hardware 3D viewport (Metal / D3D11 / OpenGL / GLES 3 with .obj/.glb models, 1024×1024 PCF soft shadows, GPU instancing and 3D particles; see 3D scenes); SpriteView(scene: $this->game) runs a fixed-timestep Game loop (game plugin).
  • Calling C, Apple Objective-C & Android Java/Kotlin APIs (ffigen & jnigen): When an app or coding agent needs a native C library, an iOS/macOS framework (AVFAudio, CoreBluetooth, LocalAuthentication), or an Android Java/Kotlin SDK class (BatteryManager, SensorManager, third-party .jar), generate type-safe PHP 8.5 bindings directly with the CLI instead of writing FFI::cdef, ObjC::msg type letters, or C JNI glue by hand (see Native interop):

```sh # 1. C header -> PHP FFI class myphp ffigen -class AudioFfi -lib libaudio.dylib -out src/Native/AudioFfi.php audio.h

# 2. Apple Objective-C header -> PHP wrapper over MyPHP\Native\ObjC myphp ffigen -objc AVAudioSession -framework AVFAudio -out src/Native/AVAudioSession.php AVAudioSession.h

# 3. Android SDK / Java class -> PHP wrapper over MyPHP\Native\Jni myphp jnigen -out src/Native/BatteryManager.php android.os.BatteryManager ```

Platform behavior you get for free

  • Light and dark mode, the system's accent, higher contrast and larger

text: the named colors and the text styles follow them. On phones, Dynamic Type (iOS's Text Size, Android's Font size) scales every Font style as the setting changes.

  • Reduce Motion (iOS; Android's "Remove animations"): springs,

transitions and page slides settle at once.

  • Right to left: leading and trailing follow the language; rows

mirror (see Right to left).

  • Accessibility: views are read by VoiceOver and TalkBack by their

text and accessibilityLabel (see Accessibility).

  • On phones: touch, the safe area, the keyboard, Back, the pickers,

long press and swipes (see Android and iOS).

Not in myphp

SwiftUIStatus
WidgetKit, App Intents, Live ActivitiesOut of scope (OS extensions)
tvOS, Android TV, visionOS, watchOSNot targeted (macOS, Windows, Linux, Android and iOS/iPadOS are supported; Device::type() reports Desktop, Mobile, Pad, Tv)

Side-by-Side Comparison: Rust Macro UI vs. Go (mygo) vs. SwiftUI vs. MyPHP

Building the exact same screen (a 32pt-padded, full-width vertical container with 16pt spacing, a title2 heading, a notifications switch, and a row with a primary button and click counter):

1. Rust Immediate-Mode UI (custom view! proc-macro)

view! { ui,
    Column(pad: 32., gap: 16., width: Size::FILL) {
        Heading("Hello, CUI", 2);
        Switch("Notifications" => notifications);
        Row(gap: 8.) {
            Button("Click me", variant: ButtonVariant::Primary) {
                clicks += 1;
            }
            Text(format!("Clicked {clicks} times"));
        }
    }
}

*Drawbacks*: Relies on non-standard proc-macro syntax (=>), opaque compiler errors when braces mismatch, long cargo build compile cycles, and format!() bakes the string before localization can see it.

2. Go (mygo imperative Begin/End builder)

c.Column(32, 16, 1).FillWidth()
  c.Text("Hello, MyGo", 22).Bold()
  c.Switch("Notifications", &s.notifications)
  c.Row(0, 8)
    if c.PrimaryButton("Click me").Clicked() {
        s.clicks++
    }
    c.Text(fmt.Sprintf("Clicked %d times", s.clicks))
  c.End()
c.End()

*Drawbacks*: Positional magic numbers (32, 16, 1) because Go lacks named arguments, manual c.End() pairing that breaks the tree if one is missed, and desktop-only.

3. Apple SwiftUI

VStack(alignment: .leading, spacing: 16) {
    Text("Hello, SwiftUI").font(.title2).bold()
    Toggle("Notifications", isOn: $notifications)
    HStack(spacing: 8) {
        Button("Click me") {
            clicks += 1
        }
        .buttonStyle(.borderedProminent)
        Text("Clicked \(clicks) times")
    }
}
.padding(32)
.frame(maxWidth: .infinity, alignment: .leading)

*Drawbacks*: Clean and expressive, but locked to Apple platforms (no Windows, Linux, or Android) and requires Xcode compilation.

4. MyPHP (Pure PHP 8.5 + SwiftUI Declarative + 5 Platforms)

$app = new class { public bool $notifications = true; public int $clicks = 0; };
$view = fn() => VStack(alignment: HorizontalAlignment::leading, spacing: 16)(
    Text('Hello, MyPHP')->font(Font::title2)->bold(),
    Toggle('Notifications', isOn: $app->notifications),
    HStack(spacing: 8)(
        Button('Click me', action: fn() => $app->clicks++)
            ->buttonStyle(ButtonStyle::borderedProminent),
        Text("Clicked {$app->clicks} times"),
    ),
)->padding(32)->frame(maxWidth: INF, alignment: Alignment::leading);

*Why MyPHP wins*:

  • 100% Standard PHP 8.5 (Zero Macros): Uses native PHP named arguments, __invoke double parentheses VStack(...)(...), and pass-by-reference (isOn: $app->notifications) with full IDE autocomplete and static analysis.
  • Zero-Wait Hot Reload & Reactive State: Save view.php and the running window updates in < 10 ms without recompiling; mutating $this->clicks++ inside async App::go() fibers or timers automatically redraws the window.
  • Smart Localization on Interpolated Strings: Text("Clicked {$app->clicks} times") automatically matches "Clicked {clicks} times" in locales/*.json and applies target-language ICU plural rules.
  • Runs Everywhere: One codebase renders natively on macOS (Metal), Windows (Direct3D 11), Linux (OpenGL 3.3), iOS (Metal), and Android (GLES 3.0).

For building apps with AI coding agents (skills, prompt templates, headless testing and visual screenshot verification), see Building with AI Agents.