SemVer through a behaviour change: choosing a version without self-deception

Three isolated coordinate generator changes: a defect fix, an optional range, and a new format. Connect version decisions to unchanged consumer expectations.

A similar shape does not guarantee the same compatibility: the exact details matter.

One change can fix a defect, another can add a feature, and a third can break an existing scenario. All three may take only a few lines. To choose a library version, we need to compare the promise made to consumers before and after the change. The size of the diff cannot explain that.

Consider a small generator of cell labels: A1, Z1, AA7. It lets us separate three decisions: a compatible fix, an optional addition, and a change to the format of an existing result. The example is independent and the data is synthetic. We ran the matrix on PHP 8.5.12: all 16 cells produced the exact planned observations. The deliberate mismatches below expose the baseline defect and contract change, rather than unexpected execution failures.

Define what is already promised

Suppose our teaching library has a stable API with a hypothetical version of 1.0.0. This is a local label for reasoning, without creating a package or tag. It contains one final class, GridLabel, which can be constructed without arguments. Its method has this signature:

public function label(int $column, int $row): string

Columns 1 through 52 correspond to A–Z, then AA–AZ. Rows 1 through 99 use decimal digits without leading zeroes. The result concatenates the letters and number exactly: label(27, 7) must produce AA7. A coordinate outside either bound throws InvalidArgumentException. The message text is not a machine contract.

We also support the named call label(column: 27, row: 7), so parameter names matter. The PHP argument documentation explains this calling style. The contract promises repeatable results without writes, network requests, or changes to the object's state.

Extension through inheritance is closed here: in PHP, final prevents a class from being extended. Consumers call the class but do not implement a shared interface. This is a deliberate limit of the teaching model, rather than universal advice for libraries. It lets us examine a method addition without a hidden obligation to change third-party implementations.

Freeze expectations before changing the candidate

Two consumers use the result differently. A table displays it as a cell label. An export writes the exact string into a synthetic document. For both, A1 and A-1 are different values, even if a person recognises the same coordinate.

Our fixtures retain literal expectations: A1 for the first cell, Z1 at the alphabet boundary, AA7 after the transition, and AZ99 for the last valid coordinate. Separate checks cover named arguments, a repeated call, and four invalid bounds: a zero and an excessive column, and a zero and an excessive row. Expectations are not computed using the candidate's own algorithm.

The baseline implementation deliberately contains one defect: for column 26 it produces @ instead of Z. The already frozen documentation requires Z1, so this scenario must expose the baseline's known mismatch. We cannot later call it a new candidate regression. The other existing examples must retain their results.

Before execution, we freeze the contract text, source files, and fixtures with checksums. This protects against silently adjusting expectations. If investigation shows that a promise was formulated incorrectly, it needs a separate revision and an explanation of the impact. Merely rewriting the expectations after a failed run would remove the subject of the comparison.

A fix: restore the promised Z

The first candidate changes only how the boundary letter is generated. The rule, signature, constructor, and valid inputs remain the same. The ordinary existing scenarios produced identical results before and after the change, while the boundary scenario changed from @1 to Z1.

This can justify a patch decision because it restores an established behaviour. SemVer 2.0.0 associates a patch with a backward compatible bug fix. For our hypothetical baseline, this is a candidate for 1.0.1, within the finite scenarios actually checked.

A consumer may nevertheless have added a workaround, replacing @ with Z or treating column 26 specially. Those places need a separate review. Calling the fix compatible with the defined contract does not guarantee a painless update for every dependency on the defect. Conversely, a workaround does not let us retroactively change the original promise to “any character”.

The decision note should identify the exact defective input, expected response, changed result, and known workarounds. Saying “improved generation” hides precisely the information an export author needs before updating.

An addition: a new method for a new scenario

For the next two experiments, we use the corrected code as the shared baseline. This lineage matters: we do not assign different contents to one version or mix a repeated fix with the evaluation of a feature. Both candidates derive independently from the same hypothetical 1.0.1.

The second candidate adds a method to the final class:

public function range(int $firstColumn, int $lastColumn, int $row): array

It returns an inclusive horizontal range. For example, columns 25–27 of the first row must produce ['Y1', 'Z1', 'AA1']. Reversed bounds and invalid coordinates throw InvalidArgumentException. The existing method does not call the new one, and the constructor acquires no dependencies or required parameters.

The existing table and export passed their unchanged fixtures. A new consumer checks a range, a single cell, and invalid bounds. The baseline has no range method: that is the expected absence of a new capability, rather than a broken existing API. In the candidate, all five new cases passed alongside the existing ones.

Under these conditions, the local decision is minor, hypothetically 1.1.0. In a model allowing third-party implementations of an interface, adding a required method would have a different impact. We would also need to revisit the conclusion if existing container configuration started requiring a new dependency. Verification must cover the entire supported path, including object construction.

A format change: the PHP type stays, the agreement changes

The third candidate also starts from the corrected baseline but does not add range. It changes A1 into A-1, and AA7 into AA-7. The method name, arguments, and string return type remain unchanged. These are valid strings to PHP; to the existing export, they are a different promised format.

We retain the existing fixtures without editing them. We observed a precise mismatch: the fixture required A1, while the process returned A-1. A neighbouring check uses an adapted consumer that expects the new format. The adapted checks passed; this shows a migration path but does not undo the break in the existing scenario.

For a stable API under SemVer, this is major, hypothetically 2.0.0. Only one concatenation operation changes, yet line count does not measure impact. Updating requires deliberate adaptation of dependent checks, formats, and export readers. Here we establish the need for adaptation; delivery to real websites is a separate task.

Change from its exact baseline Key expectation Conditional decision
Defective baseline → fix @1 becomes the promised Z1; other existing scenarios are preserved Patch: 1.0.1
Corrected baseline → range Existing calls stay unchanged; the new method is optional Minor: 1.1.0
Corrected baseline → hyphen An existing fixture sees the exact change A1 → A-1 Major: 2.0.0

Keep the question fixed throughout the comparison

Each pair should change only the behaviour being investigated. If the hyphen candidate also fixes the alphabet boundary, adds ranges, and changes the accepted rows, a failed export becomes harder to explain. Isolation does not itself improve the code; it makes the causal conclusion testable.

We also separate the assessment from permission to release. A team may have its own process for approving version numbers, checking dependencies, and publishing artifacts. A teaching classification does not start that process or allow an automatic version increase for a real package. If an organisational constraint prevents the required transition, incompatibility should not be disguised as a patch: restore compatible behaviour or make a separate decision about changing the contract.

For reproducibility, we also preserve the distinction between the existing and adapted consumers. The latter answers whether the new agreement is usable. The former answers a different question: will a supported existing scenario survive the update? Keeping only the adapted fixture would remove the evidence behind the major decision.

Separate a behavioural mismatch from a broken execution

Each matrix cell runs in a separate PHP process with one selected class variant. Classes with identical names cannot collide, and one scenario's state cannot leak into the next. All variants need a syntax check before behavioural checks begin.

A nonzero exit code alone is insufficient. A working process must return a structured observation: the fixture name, exact expected and actual values, exception type, and list of mismatches. Missing PHP, a syntax error, or an invalid worker response indicates an execution problem. None proves that the API format became incompatible.

The example is added to one existing Symfony application as isolated fixtures and checks. It needs no second application, new Kernel, or separate dependencies. The integration check obtained the corrected GridLabel from the existing container. Separately, Composer distinguishes dependency selection from installation using a lock file; neither operation itself checks the exact string A1.

What actually ran

The matrix contained 4 cells for the fix, 6 for the addition, and 6 for the format change. Across 16 fresh PHP processes, it produced 70 assertion observations. The outer runner exited with code 0: every worker response and exit code matched the exact protocol. This includes expected negative controls; it does not mean that every existing consumer accepted every candidate.

The defective baseline returned @1 instead of Z1; the fix preserved the existing scenarios. Before the addition, range was absent in exactly five new cases; after the addition, they passed. The format change produced four value mismatches in the existing suite and one at the alphabet boundary; exception checks remained stable. Three adapted checks passed with the new format and produced the exact mismatches with the old format.

Separately, syntax checks of all four snapshots, the Symfony container check, and one PHPUnit test with three assertions passed: A1, Z1, and AZ99 from the real service. These are not 70 PHPUnit assertions: the matrix has its own protocol. Execution used Symfony 8.1, PHP 8.5.12, and PHPUnit 13.4.6. The PHP minimum for this Symfony application with its tests is 8.4.1; the standalone worker does not establish compatibility of the whole application with PHP 8.4.0. Other PHP versions were not run.

For each candidate, we retain a short decision: the established promise, exact baseline, existing consumer's observation, need for adaptation, and unknown risks. Even a complete set of successful fixtures proves only the scenarios checked. A semantic version communicates the accepted level of change; its reliability depends on an honest comparison. The hypothetical numbers here are not released versions and do not rewrite the contents of an already published release.

  1. Vendors & Packages A package’s public contract extends beyond method signatures
  2. Conformance Deprecated now, removed later: managing a package API migration
  3. Vendors & Packages What a changelog should explain: from file lists to user behavior
  4. Platform Engineering Consumer contract tests: catch a break before upgrading the site