Repository navigation
feat: a PHP# template shows an int, a float, a string or a bool, and a bool as true or false - #83
Merged
Merged
Conversation
…a bool as true or false
Problem
A PHP# developer writes `` `Paid: ${isPaid}` `` and expects "Paid: true".
A template passed every value to PHP's string conversion, so a `bool`
printed `1` or nothing. An enum, a collection or an object fell through to
PHP's runtime error, "Cannot cast object of type `Plain` to `string` because
it does not implement `Stringable`", which tells the developer to write
`__toString()`, a method PHP# refuses. The spec did not say which values a
template shows.
Solution
Spec section 18 states the rule, and decision 70 records it with Kotlin
and C# as precedent:
- A template's `${expr}` accepts `int`, `float`, `string` and `bool`, and a
`bool` prints `true` or `false`.
- Every other type is a compile error: "A template shows `int`, `float`,
`string` or `bool`, and `Status` is none of them.", naming the type.
- A nullable value is refused until it is checked, as section 24 states.
- A plain PHP file keeps PHP's own interpolation.
`SHARP_MAGO_COMMIT` moves to mago-sharp d87f79a, whose checker gives the
error and whose bridge lowers a `bool` part as `value ? "true" : "false"`.
The header the bridge generates at that commit differs from this one only
in that line.
docs/
├── spec.md <- section 18: the rule, the bool text, the message, five examples
└── decisions/070-template-values.md <- new: chosen, two rejected options, precedent, spec
ext/sharp/sharp_unit.h <- SHARP_MAGO_COMMIT d87f79a
Zend/tests/sharp/
├── Template.sharp <- paid(bool): `Paid: ${isPaid}`
└── template.phpt <- prints "Paid: true" and "Paid: false"; title states the rule
…pin the one-instruction bool lowering Problem `template.phpt` showed a `bool` printing `true` and `false`, but no line showed `int`, `float` and `string` interpolating as before in the same template. Decision 70 linked Kotlin and C# without quoting them, and neither it nor spec section 18 said that a union such as `int|string` is refused. mago-sharp#110 now lowers a `bool` part in one instruction. Solution - `Template::totals(int, float, string)` prints "Total: 3, ratio 1.5, name cart", and `template.phpt` expects it. - Spec section 18 and decision 70 state that `int|string` is refused. - Decision 70 quotes Kotlin's and C#'s documentation and `Boolean.ToString`. - `SHARP_MAGO_COMMIT` moves to mago-sharp 6a5b4f1, whose bridge lowers a `bool` part as `["false", "true"][value]`, one FETCH_DIM_R after the optimizer. The generated header differs only in that line, and `SHARP_UNIT_ABI` is unchanged. docs/ ├── spec.md <- section 18: a union such as int|string is refused └── decisions/070-template-values.md <- refused unions; Kotlin and C# quoted ext/sharp/sharp_unit.h <- SHARP_MAGO_COMMIT 6a5b4f1 Zend/tests/sharp/ ├── Template.sharp <- totals(int, float, string) └── template.phpt <- expects "Total: 3, ratio 1.5, name cart"
…h a template shows
Problem
Spec section 21's `match` example shows `` `Continue at ${redirect}` ``
with `redirect` bound as a `Url`. Section 18 now refuses every template
part that is not an `int`, a `float`, a `string` or a `bool`, so the spec
showed code its own rule refuses. The spec declares no `Url` type and gives
it no text form. The standard library's `Sharp.Net.Url` is a static class
of string helpers with no instances, so it cannot hold a field's value.
Solution
`PaymentResult.RequiresAction` carries `string redirect`, in the enum's
declaration in section 20 and in the `match` arm in section 21. The arm
then shows a `string`, which section 18 accepts.
docs/
└── spec.md <- section 20: case RequiresAction(string redirect);
section 21: PaymentResult.RequiresAction(string redirect) => `Continue at ${redirect}`,
Problem `SHARP_MAGO_COMMIT` named 6a5b4f1, the head of mago-sharp#110 before it merged. php-sharp pins only commits on mago-sharp's master. Solution `ext/sharp/sharp_unit.h` is the header the bridge generates at a59162f, the merge commit of mago-sharp#110. It differs only in `SHARP_MAGO_COMMIT`. `SHARP_UNIT_ABI` is unchanged, and `regen-sharp-kinds.php` reproduces that commit's `kind.rs` with an empty diff. ext/sharp/sharp_unit.h <- SHARP_MAGO_COMMIT a59162f
…-values # Conflicts: # ext/sharp/sharp_unit.h
heyJordanParker
added a commit
that referenced
this pull request
Oct 10, 2026
…010d53 Master pins Mago a59162f, the merge of mago-sharp#110, and this branch pinned b68a9c4, the head of mago-sharp#101. Neither commit holds the other's checker. Mago master 4010d53, the merge of mago-sharp#113, holds #101 and #110, so the merge pins it. The header that the bridge at 4010d53 builds matches this file exactly, so only `SHARP_MAGO_COMMIT` moves and `SHARP_UNIT_ABI` is unchanged. ext/sharp/ sharp_unit.h SHARP_MAGO_COMMIT is 4010d53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A PHP# developer writes
`Paid: ${isPaid}`and expects "Paid: true". A template passed every value to PHP's string conversion, so aboolprinted1or nothing. An enum, a collection or an object fell through to PHP's runtime error, "Cannot cast object of typePlaintostringbecause it does not implementStringable", which tells the developer to write__toString(), a method PHP# refuses.Solution
Spec section 18 states the rule, the
booltext and the exact message:The error is "A template shows
int,float,stringorbool, andStatusis none of them.", with the offending type's PHP# name. A literal or narrowed type counts as its base type. A union such asint|stringis none of the four and is refused.int?is refused until it is checked, as section 24 already states. A plain PHP file keeps PHP's own interpolation.Section 21's
matchexample showed`Continue at ${redirect}`withredirectbound as aUrl, which the new rule refuses. The spec declares noUrland gives it no text form. The standard library'sSharp.Net.Urlis a static class of string helpers with no instances. SoPaymentResult.RequiresActionnow carriesstring redirect, in its declaration in section 20 and in the arm in section 21.Decision 70 records it. It chooses
int,float,stringandboolwith aboolprinted by name, quoting Kotlin (true) and C# (True). It rejects only numbers and strings (Elm) and a default text for anything (Swift and JavaScript). Each option shows the same five lines.SHARP_MAGO_COMMITmoves to a59162f, the merge commit of heyJordanParker/mago-sharp#110. That commit's checker gives the error. Its bridge lowers aboolpart as["false", "true"][value], oneFETCH_DIM_Rafter the optimizer. The header the bridge generates at that commit differs from this one only in the commit line, andSHARP_UNIT_ABIis unchanged.Verification
template.phpton the old pin 58c7c4a printsPaid: 1andPaid:, and fails.php -lcompiles all 74 fixtures.mago compileat 6a5b4f1 compiles all 96.sharpfiles and refuses none, so no fixture or library file changed.regen-sharp-kinds.phpat 6a5b4f1 reproduceskind.rswith an empty diff.regen-sharp-kinds.phpreproduceskind.rswith an empty diff. The generated header differs only inSHARP_MAGO_COMMIT.mago compilecompiles all 96.sharpfiles, andtemplate.phpt,phpversion_sharp.phptandri_sharp.phptpass in plain mode and under both JITs.php --ri sharpprintsMago commit => a59162f6e8f08ff6b7358abee0ca3b71907e00e6.sharp/bin/testcompiles onlyZend/tests/sharp/*.sharp, the harness and the library, and nothing readsdocs/spec.md.`Continue at ${redirect}`withstring redirectcompiles. With an object it gets "A template showsint,float,stringorbool, andRedirectis none of them."