Skip to content

Conversation

@samsonasik
Copy link
Member

No description provided.

Copy link
Member

@TomasVotruba TomasVotruba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @calebdw

@samsonasik
Copy link
Member Author

@TomasVotruba ready 👍

@TomasVotruba TomasVotruba merged commit 367edb5 into main Jan 28, 2026
57 checks passed
@TomasVotruba TomasVotruba deleted the skip-with-include branch January 28, 2026 16:10
@TomasVotruba
Copy link
Member

LGTM 👍

@calebdw
Copy link
Contributor

calebdw commented Jan 28, 2026

@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---declare(strict_types=1) only affects the file that it is defined in and not code in other files

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, world

In short, it is perfectly safe to add declare(strict_types=1); to a file that includes non-strict code as long as that file itself uses strict types

@samsonasik
Copy link
Member Author

@calebdw I see, I just realize that declare(strict_types=1) is file scoped, let's revert :)

@calebdw
Copy link
Contributor

calebdw commented Jan 28, 2026

Thanks! I've found it's important to test assumption about strict_types because it's not always immediately obvious

@TomasVotruba
Copy link
Member

@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?
I think people should know about this gold :)

@calebdw
Copy link
Contributor

calebdw commented Jan 28, 2026

Wow, I would love to! I've never written a blog post before though 😅, any tips?

@TomasVotruba
Copy link
Member

@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:

  • Why it's important?
  • How it works?
  • 2-3 examples
  • Try it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants