With this libraries you are able to use benefits with strong typing in PHP 5 & 7
- Collections with Data Models as Objects
- Units as Objects with Conversion between Units
- Calculator with all operations as Objects
With Phunc library I share ideas practice software examples. "how to use simple functional PHP with usage objecting representation" utilities for functional programming.
If you are not happy with functions in PHP to implements functional programming, try to use objects. PHP objects can help with:
- define
- transport
- conversion
- controlling
class Dump
{
public function __construct(ArrayObject $array)
{
// first variable
try {
if(empty($array->first)){
throw new Exception('Undefined property: first');
}
var_dump($array->first);
} catch( Exception $e ) {
echo 'Problem with ' . $e->getMessage() . "\n";
}
// second variable
try {
if(empty($array->second))
{
throw new Exception('Undefined property: second');
}
var_dump($array->second);
} catch( Exception $e ) {
echo 'Problem with ' . $e->getMessage() . "\n";
}
}
}
$a = new ArrayObject();
new Dump( $a );
Problem with Undefined property: first
Problem with Undefined property: second
$a = new ArrayObject();
$a->first = 1;
new Dump( $a );
int(1)
Problem with Undefined property: second
$a = new ArrayObject();
$a->first = 1;
$a->second = 2;
new Dump( $a );
int(1)
int(2)
dot phunc install
Add the phunc library to your applications composer.json file:
composer require tom-sapletta-com/phunc
{
"require": {
"tom-sapletta-com/phunc": "*"
}
}
Now tell composer to download the library by running the following command:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Composer will install the bundle into your project's vendor/tom-sapletta-com/phunc
directory.
Add the config classes in new folder config/
InfoPath.php
ErrorPath.php
Add the temporary folder tmp/
namespace Config;
class ErrorPath
{
function __toString()
{
return '../tmp/error.log.txt';
}
}
(string) new ErrorPath();
see Todo List here
Thanks goes to these wonderful people
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind are welcome!