1. Go to this page and download the library: Download respect/stringifier library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
respect / stringifier example snippets
echo Respect\Stringifier\stringify($value);
$stringify = Respect\Stringifier\Stringify::createDefault();
// with the `value` method
echo $stringify->value($value);
// with the `__invoke` method
echo $stringify($value);
use Respect\Stringifier\Stringifier;
use Respect\Stringifier\Stringifiers\CompositeStringifier;
use Respect\Stringifier\Stringify;
$compositeStringifier = CompositeStringifier::createDefault();
$compositeStringifier->prependStringifier(new class implements Stringifier {
public function stringify(mixed $raw, int $depth): ?string
{
if (is_object($raw) && method_exists($raw, 'toString')) {
return $raw->toString();
}
return null;
}
});
$stringify = new Stringify($compositeStringifier);
echo $stringify->value(new class {
public function toString(): string
{
return 'Hello, world!';
}
});
// Hello, world!
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.