-
-
Notifications
You must be signed in to change notification settings - Fork 431
[TypeDeclaration] Skip with include on SafeDeclareStrictTypesRector #7862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
TomasVotruba
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
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:
|
No description provided.