PHPackages                             lechimp-p/php-formlets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lechimp-p/php-formlets

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lechimp-p/php-formlets
======================

Composable forms(let)s, "The Essence of Form Abstraction" in PHP

0.7.0(11y ago)4182MITPHP

Since Apr 29Pushed 11y ago1 watchersCompare

[ Source](https://github.com/lechimp-p/php-formlets)[ Packagist](https://packagist.org/packages/lechimp-p/php-formlets)[ Docs](https://github.com/lechimp-p/php-formlets)[ RSS](/packages/lechimp-p-php-formlets/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/2d85e61cdac877f99773e71cee70d57bf4dec683537db0a71a36b0c3e1a2477e/68747470733a2f2f7472617669732d63692e6f72672f6c656368696d702d702f7068702d666f726d6c6574732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lechimp-p/php-formlets)[![Scrutinizer](https://camo.githubusercontent.com/a76e7d66dc63da70edb9e91babfb8f36d2ca109da069f57e632585237499e269/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656368696d702d702f7068702d666f726d6c6574732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lechimp-p/php-formlets)[![Coverage](https://camo.githubusercontent.com/d2e1abef6dee63f93c24aceaaa5317ce8df9636c60906e3e92165f619744767b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656368696d702d702f7068702d666f726d6c6574732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/lechimp-p/php-formlets)

php-formlets
============

[](#php-formlets)

**Create highly composable forms in PHP. Implementation of ideas from "The Essence of Form Abstraction" from Cooper, Lindley, Wadler and Yallop.**

Writing up formulars is a big part in the every days business of PHP-developers. To ease this work, one would like to abstract the formulars in a way that makes them composable. This is the implementation of an attempt to this problem grown from functional programming and [elaborated scientifically](http://groups.inf.ed.ac.uk/links/papers/formlets-essence.pdf).

It could be usefull for educational purpose, since it implements some interesting concepts. I'm also interested in real world applications of the code, but i'm not quite sure, weather the code is really ready for that atm. The concepts used in the implementation might feel somehow strange to PHPers anyway (and others as well), so i will start with some explanation of the concepts and how one could use them for a framework to create forms. Hf.

*This README.md is also a literate PHP-file.*

*This code is released under the [MIT License](LICENSE.md)*

Functions as Values, Currying
-----------------------------

[](#functions-as-values-currying)

To understand the first important ingredient of the formlet abstraction, we need to look at functions in a different way then we are used to from PHP.

The functions we need for this abstraction could be used as ordinary values, that is they can be stored in a variable, being passed around or used as an argument to another function. Functions in PHP in opposite are not that volatile, mostly you call them by their name. You could off course use some PHP magic like $function\_name() to come a bit closer to the afformentioned property of functions and PHPs callable aims at this direction.

The functions in our abstraction also all need to have an arity (that is amount of arguments) of one. How to do something like explode(" ", $foo) then, you might wonder. Easy. Since functions are ordinary values in our abstraction, you just create a function that takes the delimiter and returns a function that splits a string at the delimiter. That also means you could call a function partially. PHP functions are rather different. You always call them at once.

```

```

The function evaluation works lazy, that is it only calculates the value when it is really needed the first time. In our case that is the moment we call `$res->get()`. You will be safe in terms of the result of function applications if you only use functions without sideeffects like writing or reading global stuff. When using functions with sideeffects, the result might be suprising.

For the later use with the formlets, values can be erroneous to catch an exception from the underlying PHP function and turn it into an error value, one can use `catchAndReify` to create a new function value.

```
