https://github.com/joomla-framework/compat
[DEPRECATED] Joomla Framework PHP Compatibility Package
https://github.com/joomla-framework/compat
Last synced: about 1 year ago
JSON representation
[DEPRECATED] Joomla Framework PHP Compatibility Package
- Host: GitHub
- URL: https://github.com/joomla-framework/compat
- Owner: joomla-framework
- License: gpl-2.0
- Created: 2013-03-01T05:42:58.000Z (over 13 years ago)
- Default Branch: 1.x-dev
- Last Pushed: 2021-09-18T09:28:05.000Z (almost 5 years ago)
- Last Synced: 2025-04-02T14:21:47.350Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 13
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# The Compat Package [](https://ci.joomla.org/joomla-framework/compat)
[](https://packagist.org/packages/joomla/compat) [](https://packagist.org/packages/joomla/compat) [](https://packagist.org/packages/joomla/compat) [](https://packagist.org/packages/joomla/compat)
This is a simple package that contains forward compatibility classes and interfaces that are registered to the global namespace
## Deprecated
The `joomla/compat` package has been deprecated. No further updates are planned.
## JsonSerializable
`JsonSerializable` is a PHP 5.4 interface that allows you to specify what data to serialize to JSON when you `json_encode` an object that implements the interface.
### Usage
Since this is a PHP 5.4 interface, the `jsonSerialize()` method does not get called automatically when `json_encode`-ing an instance of the class when used in 5.3. To work around this, simply call the `jsonSerialize()` method directly when passing it to `json_encode`. This is forward-compatible with PHP 5.4.
Note in some instances of PHP 5.5 from Debian the interface is also missing (see http://stackoverflow.com/questions/18239405/php-fatal-error-call-to-undefined-function-json-decode) which will also require this interface to be included.
```php
class MyClass implements \JsonSerializable
{
/**
* @var array Holds the data this class uses.
*/
protected $data;
public function __construct(array $data)
{
$this->data = $data;
}
public function jsonSerialize()
{
return $this->data;
}
}
$obj = new MyClass(array('sample', 'data', 'to', 'encode'));
$encoded = json_encode($obj->jsonSerialize());
```
## Installation via Composer
Add `"joomla/compat": "~1.0"` to the require block in your composer.json and then run `composer install`.
```json
{
"require": {
"joomla/compat": "~1.0"
}
}
```
Alternatively, you can simply run the following from the command line:
```sh
composer require joomla/compat "~1.0"
```