Skip to content

Instantly share code, notes, and snippets.

@pschultz
Created November 23, 2016 12:29
Show Gist options
  • Save pschultz/32b325559154538d0e1b92457ffc2af2 to your computer and use it in GitHub Desktop.
Save pschultz/32b325559154538d0e1b92457ffc2af2 to your computer and use it in GitHub Desktop.
Why PHP's declare(strict_types=1); everywhere is impossible
<?php declare(strict_types=1);
require 'library.php';
public_library_function();
<?php
// Code you don't control and prefers coersive typing (e.g., not strict).
//
// public_library_function knows for a fact that $x is the string
// representation of a number. They would like to leverage coersive type
// declarations in private_library_function to automatically "cast" to int. But
// obviously *we* decide whether typing is coersive or strict.
function public_library_function() {
$x = function_returning_a_string();
private_library_function($x);
}
function private_library_function(int $x) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment