-
Notifications
You must be signed in to change notification settings - Fork 74
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
PHP 8.2: Dynamic properties deprecated, but are currently required for JobData? #377
Comments
OK, I see what's going on here, if we rely on dynamic properties we end up here https://github.com/symbiote/silverstripe-queuedjobs/blob/4/src/Services/AbstractQueuedJob.php#L256 /**
* Convenience methods for setting and getting job data
*
* @param mixed $name
* @param mixed $value
*/
public function __set($name, $value)
{
if (!$this->jobData) {
$this->jobData = new stdClass();
}
$this->jobData->$name = $value;
} If we use regular properties, Unfortunately the only other way to set jobData, is this, which has a bunch of parameters that we do not want /**
* @param int $totalSteps
* @param int $currentStep
* @param boolean $isComplete
* @param stdClass $jobData
* @param array $messages
*/
public function setJobData($totalSteps, $currentStep, $isComplete, $jobData, $messages)
{
$this->totalSteps = $totalSteps;
$this->currentStep = $currentStep;
$this->isComplete = $isComplete;
$this->jobData = $jobData;
$this->messages = $messages;
} In PHP 8.2, dynamic properties are deprecated so will throw deprecation errors, and will be removed in PHP 9 where they will throw hard exceptions Option for PHP 8.2 support are: I'm presuming b) will only work for PHP ^8.2 and will not work for PHP 9, so we'll need to implement a) regardless at some point |
@emteknetnz I think we still want all of the properties that are in the Perhaps there is an option c) Add the I'm thinking that it could probably be something very simple, like Modules/projects that want to get ahead of the curve could start defining their properties (which will not get picked up by the current |
If you're happy to do a PR here, please target at the Probably also a good time to add in the |
Saweeet, thanks for the suggestions. I should be able to pick this up in the coming days. |
I had a go at adding forward support (while keeping the status quo for BC), and I don't think it's possible for us to support both. Basically... The module itself uses dynamic properties all over the place. This means that there could be code out there that is accessing those dynamic properties either to
It's like... either way, you make read or write non backwards compatible. I think that this will need to be a breaking change whenever we decide to remove the dynamic properties. Which I guess we'll do for PHP 8.2? |
Unless I’m missing something, we don’t need to remove dynamic properties. We can add the The RFC states that PHP 9.0 will throw an
|
Re-looking at this at part of the wider adding PHP 8.2 issue - this should be fine in PHP 8.2 and I don't think we even need the AbstractQueuedJob already has a defined stdClass DOES allow dynamic properities in PHP 8.2 Any setting of a dynamic properities of a job e.g. $job->lorem = 'ipsum'; will result in a call to public function __set($name, $value)
{
if (!$this->jobData) {
$this->jobData = new stdClass();
}
$this->jobData->$name = $value;
} This method will still work in PHP 8.2 - see https://stitcher.io/blog/deprecated-dynamic-properties-in-php-82#implementing-__get-and-__set-still-works! |
Sounds like this is a non-issue. Closing. |
https://wiki.php.net/rfc/deprecate_dynamic_properties
I've been struggling a bit to understand how/where
jobData
is determined, but from manual testing it seems that it relies on us adding dynamic properties(?). EG: If I add a dynamic property to myJob
class, then whatever value is saved in that property will persist in theSavedJobData
, but as soon as I define that property on myJob
class, it seems to no longer get persisted inSavedJobData
.Does anyone have any thoughts on what the path forwards is, or perhaps I'm just missing something in the way that I implement my
Job
classes?Generally speaking, they go something like this..
Defined properties:
Dynamic properties:
The text was updated successfully, but these errors were encountered: