The strongest side of PHP
With this libraries you are able to use benefits with strong typing in PHP 5 & 7, (*1)
- Collections with Data Models as Objects
- Units as Objects with Conversion between Units
- Calculator with all operations as Objects
Apache2 requests, (*2)
introduction
With Phunc library I share ideas practice software examples.
"how to use simple functional PHP with usage objecting representation"
utilities for functional programming., (*3)
Phunctional thinking
If you are not happy with functions in PHP to implements functional programming, try to use objects.
PHP objects can help with:, (*4)
- define
- transport
- conversion
- controlling
Example functional programming with strong typing
Example PHP CLASS
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";
}
}
}
1. Example without parameters
Code
$a = new ArrayObject();
new Dump( $a );
Result
Problem with Undefined property: first
Problem with Undefined property: second
2. Example with first parameter
Code
$a = new ArrayObject();
$a->first = 1;
new Dump( $a );
Result
int(1)
Problem with Undefined property: second
3. Example with both parameters
Code
$a = new ArrayObject();
$a->first = 1;
$a->second = 2;
new Dump( $a );
Result
int(1)
int(2)
, (*5)
, (*6)
packagist phunc, (*7)
Install in PHPstorm based on composer project
, (*8)
Easy way to install Phunc with APICRA
first install apicra:
install Phunc over apicra
dot phunc install
Install Phunc
Add the phunc library to your applications composer.json file:, (*9)
composer require tom-sapletta-com/phunc
{
"require": {
"tom-sapletta-com/phunc": "*"
}
}
Install Composer
Now tell composer to download the library by running the following command:, (*10)
Linux
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Windows
``` bash
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');", (*11)
Composer will install the bundle into your project's `vendor/tom-sapletta-com/phunc` directory.
### How to start?
Add the config classes in new folder `config/`
InfoPath.php
ErrorPath.php, (*12)
Add the temporary folder `tmp/`
#### Creating example class ErrorPath
namespace Config;, (*13)
class ErrorPath
{
function __toString()
{
return '../tmp/error.log.txt';
}
}, (*14)
#### using example class ErrorPath
(string) new ErrorPath();
```, (*15)
Todo List
see Todo List here, (*16)
Contributors
Thanks goes to these wonderful people, (*17)

Tom Sapletta,
Project Leader
, (*18)
This project follows the [all-contributors][all-contributors] specification.
Contributions of any kind are welcome!, (*19)
LICENSE
APACHE2, (*20)