Created
November 23, 2016 12:29
-
-
Save pschultz/32b325559154538d0e1b92457ffc2af2 to your computer and use it in GitHub Desktop.
Why PHP's declare(strict_types=1); everywhere is impossible
This file contains 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
<?php declare(strict_types=1); | |
require 'library.php'; | |
public_library_function(); | |
This file contains 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
<?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