PHP code example of gabrielelana / precious

1. Go to this page and download the library: Download gabrielelana/precious 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/ */

    

gabrielelana / precious example snippets




use Precious\Precious;

final class Point extends Precious
{
    public static function from(int $x, int $y) : self
    {
        return new self(['x' => $x, 'y' => $y]);
    }

    protected function init() : array
    {
        return [
            self::, 1);
assert($p3 != $p4);
assert(spl_object_hash($p3) !== spl_object_hash($p4));
assert($p1 != $p3);
assert($p1 == $p4);



use Precious\Precious;

final class Point extends Precious
{
    public static function from(int $x, int $y) : self
    {
        return new self(['x' => $x, 'y' => $y]);
    }

    protected function init() : array
    {
        return [
            self:: PHP_EOL;
    // Will raise: Property Point::$x is not writable
    $p->x = 2;
    // Will raise: Parameter #1 $s of function doSomethingWith expects string, int given
    doSomethingWith($p->x);
}

function doSomethingWith(string $s) : string {
    return $s;
}