Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to assign class properties when extending Mosquitto\Client with php 7.4 #126

Open
blacktek opened this issue Dec 11, 2021 · 0 comments

Comments

@blacktek
Copy link

Hello,
I'm porting an application from a raspberry pi3 b+ (using php 5.6) to raspberry pi4 (using php 7.4)

The same class I wrote in the past that extends Mosquitto\Client is not working anymore.

My system is configured like this:

$ php --ri mosquitto

mosquitto

Mosquitto support => enabled
Compiled as dynamic module
libmosquitto version => 2.0.11
Extension version => 0.4.0

$ php -v
PHP 7.4.25 (cli) (built: Oct 23 2021 21:53:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies

$ uname -a
Linux myserver 5.10.63-v7l+ #1488 SMP Thu Nov 18 16:15:28 GMT 2021 armv7l GNU/Linux

$ dpkg -l | grep mosquitto
ii libmosquitto-dev:armhf 2.0.11-1 armhf MQTT version 5.0/3.1.1/3.1 client library, development files
ii libmosquitto1:armhf 2.0.11-1 armhf MQTT version 5.0/3.1.1/3.1 client library
ii mosquitto 2.0.11-1 armhf MQTT version 5.0/3.1.1/3.1 compatible message broker

This is a part of my class:

class MqttClient extends Mosquitto\Client {

protected $connected = false;
    
public function __construct($id = null, $cleanSession = true) {
    
    $this->x = 4; // implicit declaration of a property
    
    var_dump($this);

   var_dump($this->connected);
}

}

When I istantiate an object of the class MqttClient I get:

$ php mqtt_test.php
object(MqttClient)#3 (1) {
["x"]=>
int(4)
}
PHP Notice: Undefined property: MqttClient::$connected in /var/www/library/MqttClient.class.php on line 35

Notice: Undefined property: MqttClient::$connected in /var/www/library/MqttClient.class.php on line 35
NULL

Bassically I'm unable to access the properties of my class. If I remove "extends Mosquitto\Client" it works; the same if I try to extend any other class.

I think there is something broken with the extension; I tried to uninstall and reinstall again the package (first install was with pecl install Mosquitto-alpha - the second, after uninstall, was with pecl install Mosquitto-beta). But no change.

Of course nothing changes if I use public instead of protected properties.

If inside the constructor I put

$z1 = new ReflectionClass($this);
print_r($z1->getProperties());

I can see the properties:

Array
(
[0] => ReflectionProperty Object
(
[name] => connected
[class] => MqttClient
)

)
$

Do you have any idea? I think there is something not working with the extension. The exact same code was working with php5.6 on pi3

Thank you!

@blacktek blacktek changed the title Unable to assign class properties when extending Unable to assign class properties when extending Mosquitto\Client Dec 11, 2021
@blacktek blacktek changed the title Unable to assign class properties when extending Mosquitto\Client Unable to assign class properties when extending Mosquitto\Client with php 7.4 Dec 11, 2021
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

No branches or pull requests

1 participant