Introducing Syngr, my attempt at an Standard Library for PHP
github.com
github.com
I'm not trying to dump on this project, quite the opposite, I hope they achieve what I was never able to. The point I'm trying to make is that I could only defend PHP for so long before I had to admit that it's a lost cause, and other languages are simply a better fit for web development.
Stuff like this should already be part of PHP, but it's not, and I'd bet good money that it never will be. But hey, we got namespaces and late static binding, things I've used maybe once each.
That's the kind of thinking I've avoided here, trying to explicitly return a boolean value, or results.
If I find a bit of free time I'll see if I can contribute anything to this, as while I've all but abandoned PHP, I'd still like to help bring a library like this in to existence :)
As a sidenote, I read somewhere recently that there is some method to the needle/haystack madness. Basically, for strings, its needle/stack, and for arrays its stack/needle. Thought I'd share that.
All that aside, kudos!
I'd expect an order of magnitude slower for most of string and number operations.
http://www.reddit.com/r/PHP/comments/1my5cv/introducing_syng...
HAHAHAHA.
1. the value types are not immutable, which will make it very hard to work with them on larger scale. You should create new instances instead of modifying the original ones, keeping the originals intact.
2. The object hierachy is borked. You are exposing way to much information. Instead of generically allowing to save values and options in the Object, you should specialize the types much more and hide the actual value.
3. You should convert the value when creating the type, using (int) for example, or throw an exception if not convertable. The current converts the values at many places, which increases the complexity of the code unnecessarily.
2. Specialise the types more how? Why would I want to hide the actual value - although I suppose I'd want to make sure that no external object can modify its value directly.
3. Like in the constructor? What about for Number, where you can pass it an int, double or float?
$string->to_upper_case() # change the original
$string->as_upper_case() # keeps original, and returns a new upper case string $x = new Number(-3.2);
$y = $x->absolute();
Then not only is $y equal to 3.2, $x is now 3.2 as well. Is this correct? If it is, I think it is non-intuitive. $x = new Number(1)
$y = clone $x;
$y->absolute();
to work with the absolute value of variable $x without actually changing $x $x = -3.2;
$y = abs($x);Although I do believe that there is value in someone forking PHP and standardising everything in this fashion... just throwing out the legacy support entirely.
I'd really like to join forces :)
So instead of
$number = new Number(4.2);
$number->tan(array(Number::TRIG_ARC))
why not just implementing it as a separate method? $number->atan();how about boxed objects?
How would I go about adding boxed objects in PHP?
How is
$number = new Number(6.9);
echo $number->ceiling() // 7
->max(array(5, 9, 49.1)) // 49.1
->floor() // 49
->sqrt() // Value
->value(); // Get raw value rather than string
better than writing it in actual functions? sqrt(
floor(
max(
5, 9, 49.1, ceil(6.9)
)
)
)And insanely inefficient. For this particular example it must be orders of magnitude slower.