Skip to content

Instantly share code, notes, and snippets.

@kharysharpe
Last active May 22, 2021 22:06
Show Gist options
  • Save kharysharpe/aa9d610110c59cfe2e7dbe1a07d04604 to your computer and use it in GitHub Desktop.
Save kharysharpe/aa9d610110c59cfe2e7dbe1a07d04604 to your computer and use it in GitHub Desktop.
PHP Variables

Brain Dump

PHP Variable Collection

Functional Programming

Inspired by https://github.com/divarvel/PHPZ Functionality can be implemented using Underscore.php - http://brianhaveri.github.io/Underscore.php/

__string($lastName)->upperCase()->value();

__integer($money)->round(2)->value();

__double($money)->add($interest)->subtract($taxes)->value();

__collection($data)->map()->reduce()->value();

OR

use PHPVar\String;
use PHPVar\Double;
use PHPVar\Collection;

$lastName = new String();

echo $lastName->set('last name')
              ->upperCase()
              ->value();

echo $lastName->set('other name')
              ->upperCase(); // magic function to return string?



$money = new Double();

$money->set(1000000)
      ->add($interest)
      ->subtract($taxes);



$money = new Double(1000000);

echo $money->add($interest)
           ->subtract($taxes);



$balances = new Collection([100, 200, 300, 400]);

$total = $balances->map()->reduce()->cast(Double::Type)->add($interest)->subtract($taxes)->value();

Should this be created?

@kharysharpe
Copy link
Author

New thoughts ....

use WISECO\PHPDataTypes\StringObject;
use WISECO\PHPDataTypes\DateObject;
use WISECO\PHPDataTypes\TimestampObject;
use WISECO\PHPDataTypes\IntegerObject;
use WISECO\PHPDataTypes\NumericObject;
use WISECO\PHPDataTypes\FloatObject;
use WISECO\PHPDataTypes\FloatObject;
use WISECO\PHPDataTypes\MoneyObject;
use WISECO\PHPDataTypes\BooleanObject;
use WISECO\PHPDataTypes\CollectObject;
use WISECO\PHPDataTypes\ArrayObject;


$string = new StringObject($value);
$date = new DateObject($value);
$timestamp = new TimestampObject($value);
$integer = new IntegerObject($value);
$numeric = new NumericObject($value);
$float = new FloatObject($value, $precision = 8);
$double = new FloatObject($value, $precision = 8);
$money = new MoneyObject($value, $precision = 8);
$boolean = new BooleanObject($value);


$string->toUppercase()->substring(2, 5);
$string->toCamelCase();

$bonus = new MoneyObject(100.143, 3);
$total = $money->add($bonus);

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