[TypeDeclaration] Skip with include on SafeDeclareStrictTypesRector#7862
[TypeDeclaration] Skip with include on SafeDeclareStrictTypesRector#7862TomasVotruba merged 4 commits intomainfrom
Conversation
|
Fixed 🎉 /cc @calebdw |
|
@TomasVotruba ready 👍 |
|
LGTM 👍 |
|
@samsonasik, did you actually run into a PHP error or are you just preemptively making this change? My testing shows that this should not have been merged--- mkdir -p /tmp/strict-test && cd /tmp/strict-test
# A non-strict included file that uses type coercion internally
cat > included.php << 'PHP'
<?php
function greet(string $name): string {
return "Hello, " . $name;
}
// Type coercion (int -> string) works because THIS file is non-strict
echo greet(123) . "\n";
PHP
# Main file WITHOUT strict_types
cat > without_strict.php << 'PHP'
<?php
include __DIR__ . '/included.php';
echo greet("world") . "\n";
PHP
# Main file WITH strict_types (what Rector would produce)
cat > with_strict.php << 'PHP'
<?php
declare(strict_types=1);
include __DIR__ . '/included.php';
echo greet("world") . "\n";
PHP
php without_strict.php
# Hello, 123
# Hello, world
php with_strict.php
# Hello, 123 <-- included file's internal call still works with NO errors!
# Hello, worldIn short, it is perfectly safe to add |
|
@calebdw I see, I just realize that declare(strict_types=1) is file scoped, let's revert :) |
|
Thanks! I've found it's important to test assumption about |
|
@calebdw Btw, I'd love to give this rule more attention. Would you open to write a simple post how/why it works, that we could publish on https://getrector.com/blog under your name? |
|
Wow, I would love to! I've never written a blog post before though 😅, any tips? |
|
@calebdw Awesome, you'll be fine 👍 Looks like you have the skill already, based on clear descriptiosn of your PR 👍 You can kick off with this structure:
|
|
Here's the blog post PR! |
No description provided.