Remove trigger_error from WooCommerce::__set (#52764)

This commit is contained in:
Néstor Soriano 2024-11-13 16:24:58 +01:00 committed by GitHub
parent 62eae71618
commit dd11871983
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: tweak
Replace trigger_error in WooCommerce::__set with an exception

View File

@ -209,13 +209,13 @@ final class WooCommerce {
*
* @param string $key Property name.
* @param mixed $value Property value.
* @throws Exception Attempt to access a property that's private or protected.
*/
public function __set( string $key, $value ) {
if ( 'api' === $key ) {
$this->api = $value;
} elseif ( property_exists( $this, $key ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error( 'Cannot access private property WooCommerce::$' . esc_html( $key ), E_USER_ERROR );
throw new Exception( 'Cannot access private property ' . __CLASS__ . '::$' . esc_html( $key ) );
} else {
$this->$key = $value;
}