Skip to content

Commit

Permalink
Fixed "public static property" in View Components (#34058)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozo committed Aug 31, 2020
1 parent 6dd25f4 commit f07657a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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

0 comments on commit f07657a

Please sign in to comment.