Skip to content

sdk/php: name identifiers via the engine (naming 5f) - #14679

Closed
vito wants to merge 3 commits into
naming/5a-go-codegenfrom
naming/5f-php-codegen
Closed

vito wants to merge 3 commits into
naming/5a-go-codegenfrom
naming/5f-php-codegen

Conversation

@vito

@vito vito commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Part 5f/N of the stack splitting #14501 (identifier casing): the PHP SDK. Plan: #14501 (comment)

Refs #13668

Stacked on #14673.

What changes for PHP

When the schema has Query.formatIdentifiers (engine views v1.0.0 and later), PHP codegen asks the engine to format every schema name and uses the result. On schemas without it, codegen keeps its legacy conversion and the output doesn't change.

schema name PHP before PHP now format
type LLM, SDKConfig, HTTPState LLM, SDKConfig, HTTPState Llm, SdkConfig, HttpState PASCAL:CAPITALIZED (PSR-1)
field withGPU, traceURL withGPU(), traceURL() withGpu(), traceUrl() CAMEL:CAPITALIZED
argument insecureSkipTLSVerify $insecureSkipTLSVerify $insecureSkipTlsVerify CAMEL:CAPITALIZED
enum value EStarGZ, OCIMediaTypes case EStarGZ case E_STAR_GZ SCREAMING_SNAKE:UPPERCASE

Only PHP identifiers change. Field names, argument names, input object fields, enum values and GraphQL type names on the wire are exactly what the schema has. For example, case E_STAR_GZ = 'EStarGZ'. Input object properties keep the schema's spelling because they are sent under their own name.

Old spellings keep working

  • Classes: only letter case changes. PHP class names are case-insensitive, so \Dagger\LLM still names \Dagger\Llm. PSR-4 autoloading would look for LLM.php, which a case-sensitive filesystem won't find. The LegacyClassNames autoloader (registered from composer files, after Composer's) finds the generated file ignoring case and emits E_USER_DEPRECATED.
  • Methods: PHP method names are case-insensitive too, so withGPU() still calls withGpu(). A method renamed beyond letter case gets a deprecated forwarder under the old name.
  • Enum cases: a renamed case keeps a deprecated constant, public const EStarGZ = self::E_STAR_GZ;. A value whose formatted name would collide with another value keeps its schema name (Gzip next to GZIP).
  • #[GraphQLType('LLM')]: this attribute is generated on classes whose PHP name differs from their GraphQL type. AbstractClient::loadObjectFromId and the module entrypoint (EntrypointCommand, through NormalizesClassName::graphQLTypeName) read it, so a function returning Llm registers as LLM. Without the attribute, the old name-based guess applies.

What's in it

  • Codegen (src/Codegen):
    • Live: SchemaGenerator calls formatIdentifiers in batches. The three formats are NewCodegenVisitor::NAME_FORMATS.
    • Offline: dagger:codegen --schema-file takes --names-file, the sidecar format of codegen introspect --names-out (FormattedNames).
  • Runtime (sdk/php/runtime): the codegen exec has no engine session, so the runtime formats the module schema's names itself (internal/names, using formatIdentifiers with the schema's __schemaVersion dictionary). It mounts them as --names-file. A schema without the API gets no file. The runtime module is bumped to engineVersion: v1.0.0, and its bindings now come from v1 views (nullable object returns, PhpSDK/introspectionJSON module names from core: name modules with engine/naming from v1.0.0-beta.21 #14669).
  • Regenerated client (sdk/php/generated): LLM*.php are renamed to Llm*.php, along with SdkConfig, HttpState and WorkspaceSdk, plus the method, parameter and enum case renames above.

Not in it

  • PR 6 material: the core renames (callID, shortSHA, FunctionCachePolicy DEFAULT/…) and the PHP "old schema names" table (RenamedCoreNames, AbstractInputObject::FIELD_NAMES). Without that table, regenerating after PR 6 would drop the old names of renamed input fields and enum values, so it belongs with PR 6.
  • Runtime bindings: sdk/php/runtime/internal/dagger/*.gen.go are taken from the final tree, not regenerated here. No generator covers them, and regenerating with the current Go codegen also moves them to the new internal/dagger/core/ layout, which is unrelated churn. Go modules regenerate their bindings at load anyway. go vet and go test pass.

Breaking changes for PHP SDK users

These only apply to code generated against a v1 schema: the client, or a module declaring engineVersion ≥ v1.0.0-0. Older modules generate exactly as before.

  1. Named arguments that use an old parameter spelling break. $ctr->from('alpine', insecureSkipTLSVerify: true) must become insecureSkipTlsVerify: true, because PHP parameter names are case-sensitive. Positional calls are unaffected. PHP has no way to alias a parameter name. This is the main hard break.
  2. Enum case names. ImageMediaTypes::OCIMediaTypes still works as a deprecated constant, but ->name is now OCI_MEDIA_TYPES. Code that compares ->name, or lists ::cases(), sees the new names. ->value and ::from() are unchanged.
  3. Reflection and string comparisons on class names. get_class($llm) returns Dagger\Llm, and $x instanceof \Dagger\LLM still works, since PHP matches class names case-insensitively. A string comparison against 'Dagger\LLM', or a match on the class name, does not.
  4. Case-sensitive filesystems with a non-Composer autoloader or a classmap-only optimized autoloader: the old spellings resolve only through LegacyClassNames, which Composer's files autoload registers.
  5. Deprecation notices: loading a class by its old spelling raises E_USER_DEPRECATED. This only matters where deprecations are turned into exceptions, e.g. in PHPUnit strict modes.

How long these deprecated spellings live is an open decision (proposed: through 1.0).

Testing

  • php-client checks: test (PHPUnit, including new tests for FormattedNames, SchemaGenerator, the visitor's names/forwarders/enum constants/#[GraphQLType], LegacyClassNames, NormalizesClassName and AbstractClient), php-stan, php-code-sniffer and api/stale, all on the rebased branch.

  • Runtime: go vet ./... and go test ./internal/names/.

  • Integration: TestPHP, 27 tests, passing. The fixture modules declare old engine versions, so this covers the legacy fallback path.

  • Manual QA against a dev engine with a PHP module on engineVersion: v1.0.0:

    • module codegen went through the runtime's names file: the ImageMediaTypes::OCI_MEDIA_TYPES case exists, and OCIMediaTypes resolves through the deprecated constant;
    • \Dagger\LLMMessageRole::USER loads via LegacyClassNames;
    • withGPU() and withGpu() both work;
    • a function declared as returning LlmMessageRole registers as LLMMessageRole.

    Returning a core enum value from a PHP function fails with cannot create enum name from map. That also happens with an unrenamed enum (NetworkProtocol), so it predates this PR.

vito added 3 commits October 14, 2026 03:23
PHP codegen asks Query.formatIdentifiers for the schema's names (or reads
them from --names-file) and names classes PASCAL/CAPITALIZED (PSR-1: Llm,
SdkConfig), methods and parameters CAMEL/CAPITALIZED (withGpu,
insecureSkipTlsVerify) and enum cases SCREAMING_SNAKE (PER_SESSION). Schemas
without formatIdentifiers keep the legacy conversion and generate the same
code.

Wire names never change. Compatibility for existing code:

- classes renamed only in letter case still resolve (PHP class names are
  case-insensitive); the LegacyClassNames autoloader finds their file on
  case-sensitive filesystems, with a deprecation notice;
- a #[GraphQLType] attribute names the GraphQL type of a class spelled
  differently, used by loadObjectFromId and the module entrypoint;
- methods renamed beyond letter case keep a deprecated forwarder;
- renamed enum cases keep a deprecated constant under the old name.

Signed-off-by: Alex Suraci <[email protected]>
Regenerate the PHP client against a schema with Query.formatIdentifiers:
classes like LLM become Llm (old spellings keep loading), methods like
withGPU become withGpu, and enum cases like EStarGZ become E_STAR_GZ with a
deprecated constant for the old name.

Signed-off-by: Alex Suraci <[email protected]>
The PHP codegen exec has no engine session, so the runtime formats the
module schema's names with Query.formatIdentifiers (with the schema's own
version's dictionary) and hands them to codegen as a --names-file sidecar.
Schemas without formatIdentifiers get no file, keeping the legacy names.

Bump the runtime module to engineVersion v1.0.0 for the API.

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Closing: the in-repo SDKs are now legacy. This work will be redone as a PR against github.com/dagger/php-sdk (identifier-casing branch) once the engine side (view-gated naming at v1.0.0-beta.20) lands. The branch is kept for reference.

@vito vito closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant