Go to file
Tonya Mork 5b5d174a30 Code Modernization: Deprecate dynamic properties in WP_Text_Diff_Renderer_Table magic methods.
The unknown use of unknown dynamic property within the `WP_Text_Diff_Renderer_Table` property magic methods is now deprecated. A descriptive deprecation notice is provided to alert developers to declare the property on the child class extending `WP_Text_Diff_Renderer_Table`.

Changes in this commit:
* Adds a deprecation notice to the `__get()`, `__set()`, `__isset()`, `__unset()` magic methods, i.e. to alert and inform developers when attempting to get/set/isset/unset a dynamic property.
* Fixes `__get()` to explicitly returns `null` when attempting to get a dynamic property.
* Fixes `__set()` by removing the value return after setting a declared property, as (a) unnecessary and (b) `__set()` should return `void` [https://www.php.net/manual/en/language.oop5.overloading.php#object.set per the PHP handbook].
* Fixes `__isset()` to return `false` if not in the `$compat_fields`, as `isset()` and `__isset()` should always return `bool`:
   * [https://www.php.net/manual/en/language.oop5.overloading.php#object.isset `__isset()` in the PHP manual] 
   * [https://www.php.net/manual/en/function.isset.php `isset()` in the PHP manual] 
* Adds a test class with happy and unhappy paths for these changes.

For backward compatibility, no changes are made to the internal declared properties listed in `$compat_fields` and accessed through the magic methods. 

For example:
A child class uses a property named `$data` that is not declared as a property on the child class. When getting its value, e.g. `$user_query->data`, the `WP_Text_Diff_Renderer_Table::__get()` magic method is invoked, the following deprecation notice thrown, and `null` returned:

>The property `data` is not declared. Setting a dynamic property is deprecated since version 6.4.0! Instead, declare the property on the class.

=== Why not remove the magic methods, remove the `$compat_fields` property, and restore the properties `public`?

tl;dr Backward compatibility.

If a plugin adds a property to `$compat_fields` array, then sites using that plugin would experience (a) an `Undefined property` `Warning` (PHP 8) | `Notice` (PHP 7) and (b) a possible change in behavior.

=== Why not limit the deprecation for PHP versions >= 8.2?

tl;dr original design intent and inform

The magic methods and `$compat_fields` property were added for one purpose: to continue providing external access to internal properties declared on `WP_Text_Diff_Renderer_Table`. They were not intended to be used for dynamic properties.

Deprecating that unintended usage both alerts developers a change is needed in their child class and informs them what to change.

References: 
* Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
* A [https://www.youtube.com/live/vDZWepDQQVE?feature=share&t=10097 live open public working session] where these changes were discussed and agreed to.
* [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties.]

Follow-up to [28525], [31135].

Props antonvlasenko, rajinsharwar, jrf, markjaquith, hellofromTonya, SergeyBiryukov, desrosj, peterwilsoncc, audrasjb, costdev, oglekler, jeffpaul.
Fixes #58898.
See #56034.

git-svn-id: https://develop.svn.wordpress.org/trunk@56354 602fd350-edb4-49c9-b593-d223f7449a82
2023-08-03 18:11:36 +00:00
.cache Build/Test Tools: Cache the results of PHP_CodeSniffer across workflow runs. 2021-11-16 14:17:26 +00:00
.devcontainer Docs: Miscellaneous formatting corrections to inline docs and whitespace. 2023-05-03 19:44:49 +00:00
.github Build/Test Tools: Run performance tests using production env vars. 2023-07-26 19:11:44 +00:00
src Code Modernization: Deprecate dynamic properties in WP_Text_Diff_Renderer_Table magic methods. 2023-08-03 18:11:36 +00:00
tests Code Modernization: Deprecate dynamic properties in WP_Text_Diff_Renderer_Table magic methods. 2023-08-03 18:11:36 +00:00
tools Editor: update npm packages with second round of bug fixes for 6.3 RC1. 2023-07-18 07:17:23 +00:00
.editorconfig General: Instruct file editors not to trim trailing whitespace in markdown files. 2018-03-20 22:14:53 +00:00
.env General: Introduce WP_DEVELOPMENT_MODE constant to signify context-specific development mode. 2023-06-26 19:55:28 +00:00
.eslintignore Build/Test Tools: Enable JSDocs to be linted with ESLint. 2020-07-27 23:33:51 +00:00
.eslintrc-jsdoc.js Build/Test Tools: Enable JSDocs to be linted with ESLint. 2020-07-27 23:33:51 +00:00
.git-blame-ignore-revs Build/Test Tools: First pass at a .git-blame-ignore-revs file. 2022-03-29 03:20:29 +00:00
.gitignore Build/Test Tools: Add a performance measurement workflow. 2023-03-03 20:37:10 +00:00
.jshintrc Emoji: Optimize emoji loader with sessionStorage, willReadFrequently, and OffscreenCanvas. 2023-06-27 17:22:59 +00:00
.npmrc Build/Test: Prevent using unsupported NPM versions. 2022-09-11 21:52:10 +00:00
.nvmrc Build/Test Tools: Specify NodeJS version 14.x in the .nvmrc file. 2021-11-24 14:05:31 +00:00
composer.json General: Increase the minimum supported version of PHP to 7.0.0. 2023-07-05 17:39:55 +00:00
CONTRIBUTING.md Build/Test Tools: Add a missing word to the CONTRIBUTING.md file. 2021-02-23 19:59:20 +00:00
docker-compose.yml Build/Test Tools: Always use the amd64 images for MariaDB and MySQL on the local development environment. 2022-09-07 17:13:43 +00:00
Gruntfile.js Build Tools: Remove outmoded jsvalidate task from Gruntfile. 2023-07-17 14:05:51 +00:00
jsdoc.conf.json Build Tools: Fix JSDoc configuration include paths. 2018-06-14 12:45:06 +00:00
package-lock.json Build/Test Tools: revert downgrade of uuid. 2023-08-03 04:57:04 +00:00
package.json Build/Test Tools: revert downgrade of uuid. 2023-08-03 04:57:04 +00:00
phpcompat.xml.dist General: Increase the minimum supported version of PHP to 7.0.0. 2023-07-05 17:39:55 +00:00
phpcs.xml.dist Editor: Update block-serialization-default-parser package for WP 6.3 Beta 1. 2023-06-27 00:43:42 +00:00
phpunit.xml.dist Build/Test Tools: Update PHPUnit configuration for PHPUnit 9.5.10/8.5.21+. 2021-09-26 03:11:18 +00:00
README.md Text Changes: Typo fix in README.md. 2023-04-26 22:26:36 +00:00
SECURITY.md Trunk is now 6.4 alpha. 2023-07-19 05:52:06 +00:00
webpack.config.js Build: Enable React Fast Refresh for block development 2022-04-11 16:08:12 +00:00
wp-cli.yml Build/Tests: Default to running unit tests from src. 2019-01-09 10:09:02 +00:00
wp-config-sample.php Help/About: Use the new /documentation/ URLs for HelpHub links in WordPress Admin. 2023-02-23 10:36:33 +00:00
wp-tests-config-sample.php Docs: Use generic references to "Database" in wp-config-sample.php. 2021-12-14 08:42:16 +00:00

WordPress

Welcome to the WordPress development repository! Please check out the contributor handbook for information about how to open bug reports, contribute patches, test changes, write documentation, or get involved in any way you can.

Getting Started

Using GitHub Codespaces

To get started, create a codespace for this repository by clicking this 👇

Open in GitHub Codespaces

A codespace will open in a web-based version of Visual Studio Code. The dev container is fully configured with softwares needed for this project.

Note: Dev containers is an open spec which is supported by GitHub Codespaces and other tools.

In some browsers the keyboard shortcut for opening the command palette (Ctrl/Command + Shift + P) may collide with a browser shortcut. The command palette can be opened via the F1 key or via the cog icon in the bottom left of the editor.

When opening your codespace, be sure to wait for the postCreateCommand to finish running to ensure your WordPress install is successfully set up. This can take a few minutes.

Local development

WordPress is a PHP, MySQL, and JavaScript based project, and uses Node for its JavaScript dependencies. A local development environment is available to quickly get up and running.

You will need a basic understanding of how to use the command line on your computer. This will allow you to set up the local development environment, to start it and stop it when necessary, and to run the tests.

You will need Node and npm installed on your computer. Node is a JavaScript runtime used for developer tooling, and npm is the package manager included with Node. If you have a package manager installed for your operating system, setup can be as straightforward as:

  • macOS: brew install node
  • Windows: choco install nodejs
  • Ubuntu: apt install nodejs npm

If you are not using a package manager, see the Node.js download page for installers and binaries.

Note: WordPress currently only supports Node.js 14.x and npm 6.x.

You will also need Docker installed and running on your computer. Docker is the virtualization software that powers the local development environment. Docker can be installed just like any other regular application.

Development Environment Commands

Ensure Docker is running before using these commands.

To start the development environment for the first time

Clone the current repository using git clone https://github.com/WordPress/wordpress-develop.git. Then in your terminal move to the repository folder cd wordpress-develop and run the following commands:

npm install
npm run build:dev
npm run env:start
npm run env:install

Your WordPress site will be accessible at http://localhost:8889. You can see or change configurations in the .env file located at the root of the project directory.

To watch for changes

If you're making changes to WordPress core files, you should start the file watcher in order to build or copy the files as necessary:

npm run dev

To stop the watcher, press ctrl+c.

To run a WP-CLI command

npm run env:cli -- <command>

WP-CLI has many useful commands you can use to work on your WordPress site. Where the documentation mentions running wp, run npm run env:cli -- instead. For example:

npm run env:cli -- help

To run the tests

These commands run the PHP and end-to-end test suites, respectively:

npm run test:php
npm run test:e2e

To restart the development environment

You may want to restart the environment if you've made changes to the configuration in the docker-compose.yml or .env files. Restart the environment with:

npm run env:restart

To stop the development environment

You can stop the environment when you're not using it to preserve your computer's power and resources:

npm run env:stop

To start the development environment again

Starting the environment again is a single command:

npm run env:start

Credentials

These are the default environment credentials:

  • Database Name: wordpress_develop
  • Username: root
  • Password: password

To login to the site, navigate to http://localhost:8889/wp-admin.

  • Username: admin
  • Password: password

Note: With Codespaces, open the portforwarded URL from the ports tab in the terminal, and append /wp-admin to login to the site.

To generate a new password (recommended):

  1. Go to the Dashboard
  2. Click the Users menu on the left
  3. Click the Edit link below the admin user
  4. Scroll down and click 'Generate password'. Either use this password (recommended) or change it, then click 'Update User'. If you use the generated password be sure to save it somewhere (password manager, etc).