When modifying existing APIs, implement changes that maintain backward compatibility while enabling new functionality. For public-facing APIs, avoid breaking changes outside of major version bumps.
When modifying existing APIs, implement changes that maintain backward compatibility while enabling new functionality. For public-facing APIs, avoid breaking changes outside of major version bumps.
Key strategies:
func_get_args()
for parameters that would break signatures@deprecated
and trigger deprecation notices@internal
annotations for components not meant for public consumption// AVOID (breaking change):
public function startTransaction(TransactionContext $context, array $customSamplingContext): Transaction;
// BETTER (backward compatible):
public function startTransaction(TransactionContext $context, ?array $customSamplingContext = null): Transaction;
// OR use implementation tricks:
public function startTransaction(TransactionContext $context): Transaction
{
// Handle optional parameter without changing signature
$customSamplingContext = func_num_args() > 1 ? func_get_arg(1) : null;
// Implementation
}
// For deprecating methods:
/**
* @deprecated since version 2.2, to be removed in 3.0
*/
public function legacyMethod(): void
{
@trigger_error(sprintf('Method %s() is deprecated since version 2.2 and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED);
// Call new implementation or keep legacy code
}
Enter the URL of a public GitHub repository