Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Using "public static property" in View Component causes an error #34058

Merged
merged 1 commit into from Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Illuminate/View/Component.php
Expand Up @@ -133,6 +133,9 @@ protected function extractPublicProperties()
$reflection = new ReflectionClass($this);

static::$propertyCache[$class] = collect($reflection->getProperties(ReflectionProperty::IS_PUBLIC))
->reject(function (ReflectionProperty $property) {
return $property->isStatic();
})
->reject(function (ReflectionProperty $property) {
return $this->shouldIgnore($property->getName());
})
Expand Down
5 changes: 5 additions & 0 deletions tests/View/ViewComponentTest.php
Expand Up @@ -23,8 +23,10 @@ public function testPublicMethodsWithNoArgsAreConvertedToStringableCallablesInvo
$component = new TestSampleViewComponent;

$this->assertEquals(0, $component->counter);
$this->assertEquals(0, TestSampleViewComponent::$publicStaticCounter);
$variables = $component->data();
$this->assertEquals(0, $component->counter);
$this->assertEquals(0, TestSampleViewComponent::$publicStaticCounter);

$this->assertSame('noArgs val', $variables['noArgs']());
$this->assertSame('noArgs val', (string) $variables['noArgs']);
Expand All @@ -36,6 +38,7 @@ public function testPublicMethodsWithNoArgsAreConvertedToStringableCallablesInvo
$this->assertArrayNotHasKey('protectedHello', $variables);
$this->assertArrayNotHasKey('privateHello', $variables);

$this->assertArrayNotHasKey('publicStaticCounter', $variables);
$this->assertArrayNotHasKey('protectedCounter', $variables);
$this->assertArrayNotHasKey('privateCounter', $variables);

Expand Down Expand Up @@ -92,6 +95,8 @@ class TestSampleViewComponent extends Component
{
public $counter = 0;

public static $publicStaticCounter = 0;

protected $protectedCounter = 0;

private $privateCounter = 0;
Expand Down