Skip to content

Fix undefined property warning in Item::__call magic method#544

Merged
pfefferle merged 1 commit intomainfrom
fix/undefined-property-warning
Dec 18, 2025
Merged

Fix undefined property warning in Item::__call magic method#544
pfefferle merged 1 commit intomainfrom
fix/undefined-property-warning

Conversation

@pfefferle
Copy link
Copy Markdown
Owner

Summary

  • Add property_exists() checks before accessing dynamic properties in get, has, and add methods
  • Prevents PHP warnings when methods like add_category() are called for properties that don't exist on the class

Test plan

  • Verify no more "Undefined property" warnings at /wp-json/webmention/1.0/endpoint
  • Test webmention processing still works correctly

Fixes #541

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes undefined property warnings that occur in PHP when the Item::__call magic method attempts to access properties that don't exist on the class, such as category. The fix adds property_exists() checks before property access in the getter, checker, and adder methods.

  • Adds property_exists() guards to prevent undefined property warnings in magic method handlers
  • Uses proper short-circuit evaluation to ensure properties are only accessed when they exist
  • Maintains backward compatibility by preserving the same behavior while eliminating warnings

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
includes/Entity/class-item.php Adds property_exists() checks in get, has, and add magic method branches to prevent accessing undefined properties
readme.md Documents the bug fix in version 5.5.1 changelog

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/entity/class-item.php Outdated
@pfefferle pfefferle requested a review from dshanske December 18, 2025 20:39
Add property_exists() checks before accessing dynamic properties in get, has, and add methods. Return empty string instead of null for non-existent properties.
@pfefferle pfefferle force-pushed the fix/undefined-property-warning branch from 15082d4 to 1243a4c Compare December 18, 2025 20:40
Copy link
Copy Markdown
Collaborator

@dshanske dshanske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works.

@pfefferle pfefferle merged commit ac8e7c4 into main Dec 18, 2025
9 checks passed
@pfefferle pfefferle deleted the fix/undefined-property-warning branch December 18, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undefined property: Webmention\Entity\Item::$category

3 participants