Skip to content

Commit f07657a

Browse files
authored
Fixed "public static property" in View Components (#34058)
1 parent 6dd25f4 commit f07657a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Illuminate/View/Component.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ protected function extractPublicProperties()
133133
$reflection = new ReflectionClass($this);
134134

135135
static::$propertyCache[$class] = collect($reflection->getProperties(ReflectionProperty::IS_PUBLIC))
136+
->reject(function (ReflectionProperty $property) {
137+
return $property->isStatic();
138+
})
136139
->reject(function (ReflectionProperty $property) {
137140
return $this->shouldIgnore($property->getName());
138141
})

tests/View/ViewComponentTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public function testPublicMethodsWithNoArgsAreConvertedToStringableCallablesInvo
2323
$component = new TestSampleViewComponent;
2424

2525
$this->assertEquals(0, $component->counter);
26+
$this->assertEquals(0, TestSampleViewComponent::$publicStaticCounter);
2627
$variables = $component->data();
2728
$this->assertEquals(0, $component->counter);
29+
$this->assertEquals(0, TestSampleViewComponent::$publicStaticCounter);
2830

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

41+
$this->assertArrayNotHasKey('publicStaticCounter', $variables);
3942
$this->assertArrayNotHasKey('protectedCounter', $variables);
4043
$this->assertArrayNotHasKey('privateCounter', $variables);
4144

@@ -92,6 +95,8 @@ class TestSampleViewComponent extends Component
9295
{
9396
public $counter = 0;
9497

98+
public static $publicStaticCounter = 0;
99+
95100
protected $protectedCounter = 0;
96101

97102
private $privateCounter = 0;

0 commit comments

Comments
 (0)