From f07657a4a8779bca384692d1b6d7f1ad77ca8e7f Mon Sep 17 00:00:00 2001 From: saku Date: Mon, 31 Aug 2020 22:21:07 +0900 Subject: [PATCH] Fixed "public static property" in View Components (#34058) --- src/Illuminate/View/Component.php | 3 +++ tests/View/ViewComponentTest.php | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/Illuminate/View/Component.php b/src/Illuminate/View/Component.php index 4e11c3162c8e..c3e37549970c 100644 --- a/src/Illuminate/View/Component.php +++ b/src/Illuminate/View/Component.php @@ -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()); }) diff --git a/tests/View/ViewComponentTest.php b/tests/View/ViewComponentTest.php index 8ceeca0dfc5b..f05ca0682bd5 100644 --- a/tests/View/ViewComponentTest.php +++ b/tests/View/ViewComponentTest.php @@ -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']); @@ -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); @@ -92,6 +95,8 @@ class TestSampleViewComponent extends Component { public $counter = 0; + public static $publicStaticCounter = 0; + protected $protectedCounter = 0; private $privateCounter = 0;