I once starting building a PHP library that was pretty much identical to this, I was really excited by the prospect of being able to write beautiful, object oriented, method chained code. Eventually I was overwhelmed by the sheer scope of what needed to be done and abandoned it. These days I work (almost) exclusively in Ruby, and life is good.
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.
Totally agree with you, and just having done the String class, I am appalled at how many different kinds of return values you can get from methods. If that's not bad enough, then PHP will throw a curveball at you with its 'this method may return falsy values'.
That's the kind of thinking I've avoided here, trying to explicitly return a boolean value, or results.
I know microbenchmarks are generally daft and horribly misapplied, but it might be worth showing/measuring the difference between using built-in procedural methods and your OO ones on some some example use cases to stop people speculating and just to make sure you aren't majorly shooting yourself in the foot perfomance wise for the benefit of a nice API.
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.
1. I had thought about that, but then I thought I'd go sort of like the Javascript route where everything can be modified (well, mostly, anyway)
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?
It looks that you don't do any checks if the object is really initialized with the value of the given type? However, if you did, then one could use this for a quick & elegant input validation and that would be extremely cool. It should check the value in the constructor and throw the exceptions if the type is wrong. And then you will also need more granular types like Integer and Float to make this more useful for everyday cases.
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.
Yeah the idea is to have something that hopefully paves over the rough parts, and who knows? One day this might be similar to what PHP will look like in the future (in a galaxy far, far away)
not going to happen ,because PHP relies to much on native extensions. If a fork doesnt work with them , it will not be successfull.
The best one can do is move to Python , which works on an httpd server and is a real multipurpose language, and it has a lot of support on shared hosts.
Hey, nice project.
I had started something very similar some time ago but I realized that the oop approach doesn't work quite well as you can't force other to use your classes.
Then I decided to go functional style, where you receive "kind of" unexpected input but produce predictable output; the result is a very simple and small api that plays nice with others.
Take a look at the code at https://github.com/eridal/prelude
I like the idea but i don't like the actual implementation. For example:
Number::tan takes an array of flags as an argument but only one flag is ever used to determine which kind of tangent method is eventually executed. For me as a user this does not only complicate the usage but it is also potentially (microoptimizationwise) slower because of the necessary condition check.
So instead of
$number = new Number(4.2);
$number->tan(array(Number::TRIG_ARC))
why not just implementing it as a separate method?
Well, PHP has four 'tan' functions, and in all fairness, I might just remove those functions altogether and leave the basic ones. I do agree that its longer to type now, but at the expense of remembering WTF atan() does.
$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
[+] [-] MattBearman|12 years ago|reply
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.
[+] [-] niteshade|12 years ago|reply
That's the kind of thinking I've avoided here, trying to explicitly return a boolean value, or results.
[+] [-] niteshade|12 years ago|reply
[+] [-] sandfox|12 years ago|reply
All that aside, kudos!
[+] [-] niteshade|12 years ago|reply
[+] [-] beberlei|12 years ago|reply
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.
[+] [-] niteshade|12 years ago|reply
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?
[+] [-] cabalamat|12 years ago|reply
[+] [-] niteshade|12 years ago|reply
[+] [-] agumonkey|12 years ago|reply
[+] [-] ivanhoe|12 years ago|reply
[+] [-] cstrat|12 years ago|reply
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.
[+] [-] niteshade|12 years ago|reply
[+] [-] unknown|12 years ago|reply
[deleted]
[+] [-] camus|12 years ago|reply
[+] [-] _lce0|12 years ago|reply
I'd really like to join forces :)
[+] [-] gh0zt|12 years ago|reply
So instead of
why not just implementing it as a separate method?[+] [-] niteshade|12 years ago|reply
[+] [-] VMG|12 years ago|reply
[+] [-] agumonkey|12 years ago|reply
[+] [-] niteshade|12 years ago|reply
[+] [-] rnts08|12 years ago|reply
[+] [-] agumonkey|12 years ago|reply
[+] [-] niteshade|12 years ago|reply
[+] [-] dancecodes|12 years ago|reply
how about boxed objects?
[+] [-] niteshade|12 years ago|reply
How would I go about adding boxed objects in PHP?
[+] [-] rorrr2|12 years ago|reply
How is
better than writing it in actual functions?[+] [-] xd|12 years ago|reply
[+] [-] niteshade|12 years ago|reply