Skip to content
Permalink
Browse files

Allow isset to check for property initialisation

Ref #2382
  • Loading branch information
muglug committed Nov 28, 2019
1 parent 4a742f9 commit 4052e6dfac18e6dbb052401b9e5dcc477e4d6215
@@ -147,18 +147,22 @@ public static function analyzeInstance(
&& $source->getMethodName() === '__construct'
&& !$context->inside_unset
) {
if (IssueBuffer::accepts(
new UninitializedProperty(
'Cannot use uninitialized property ' . $var_id,
new CodeLocation($statements_analyzer->getSource(), $stmt),
$var_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
if ($context->inside_isset) {
$stmt_type->initialized = true;
} else {
if (IssueBuffer::accepts(
new UninitializedProperty(
'Cannot use uninitialized property ' . $var_id,
new CodeLocation($statements_analyzer->getSource(), $stmt),
$var_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
$stmt_type->addType(new Type\Atomic\TNull);
$stmt_type->addType(new Type\Atomic\TNull);
}
}
}
@@ -1794,6 +1794,25 @@ private function bar(): void {
}
}',
],
'allowIssetOnTypedProperty' => [
'<?php
class A {
public string $a;
public function __construct(bool $b) {
if ($b) {
$this->a = "hello";
}
if (isset($this->a)) {
echo $this->a;
$this->a = "bello";
}
$this->a = "bar";
}
}'
],
];
}

0 comments on commit 4052e6d

Please sign in to comment.
You can’t perform that action at this time.