Skip to content

Instantly share code, notes, and snippets.

@Danack
Created October 12, 2021 17:19
Show Gist options
  • Save Danack/db8d45d88dc49a64f7e340274a982af6 to your computer and use it in GitHub Desktop.
Save Danack/db8d45d88dc49a64f7e340274a982af6 to your computer and use it in GitHub Desktop.
package_migration_easier.md

PHP 8.2 - Add packages, and allow people to opt into settings

$options = [
  'compile' => [
    'strict_properties' => 'strict'
  ]
];

package_register('NewCode', $options);

$options = [
  'compile' => [
  ]
];

package_register('OldCode', $options);

For people who don't set that setting, or have code that isn't in a package, there is no change. But internals start telling people, if you want to have easier upgrades, start putting your code into packages, so that BC breaks are easier to manage.

PHP 8.3 - Start warning that the default setting will change.

$options = [
  'compile' => [
  ]
];

package_register('OldCode', $options); // gives warning that 'strict_properties' will change default in next version

Users can turn off the warning by explicitly setting 'no'

$options = [
  'compile' => [
    'strict_properties' => 'no'
  ]
];

package_register('OldCode', $options); // no warning.

PHP 8.4 - default changes

People who have put their code in packages can manage their changes. People who have code outside of packages will inevitably still whine.

PHP 8.5 - deprecate non-strict properties except when extending StdClass

$options = [
  'compile' => [
    'strict_properties' => 'no'
  ]
];

package_register('OldCode', $options); // Warning, 'strict_properties is deprecated, extend StdClass if you want to keep the behaviour'

PHP 9.0 - Remove the option of setting strict_properties to anything other than 'strict'.

$options = [
  'compile' => [
    'strict_properties' => 'no'
  ]
];

package_register('OldCode', $options); // throw error - 'strict_properties is gone'

Doing it like that means that: i) people can opt into it. ii) people can migrate chunks of an application at a time, rather than having to touch the whole of an app at once. iii) Code can work on multiple versions of PHP, which makes upgrading far easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment