Re: PHP 5 && OO && performance && exceptions
| From: | Jochem Maas | Date: | Fri, 11 Nov 2005 14:50:44 +0000 |
| Subject: | Re: PHP 5 && OO && performance && exceptions | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-225611@lists.php.net to get a copy of this message | ||
read the internals@ archive - there is a chap there who is developing an php module
that makes objects wrappers for basic types available.
but imho:
$str = new String("W T F !!!!!!!!!!!!!!!!!!");
echo $str->getValue(), $str, $str->__toString();
is just a bit OTT. also creating and rolling out (to a group of
developers) a set of classes to use in place of basic types on the basis
of a _belief_ that it may eliminate some development errors seems to be
not an unsound basis for such as decision.
chances are that half the time developers will 'forget' the
'basetype' classes, your dealing with egos you know :-).
but then again maybe in a couple of years we will only have objects to
represent types - although so long as at least Rasmus is 'on the bridge'
of starship NCC-17-PHP I imagine that won't be happening - IFAIR the creator is a fan
of straigtforward procedural code in most cases - apologies to Rasmus if I misread him.
cron@odi.com.br wrote:
Some more thought. To solve this problem would be necessary to create some utility class like System in java and that way should be possible to do a System::echo($string) based on type, i guess this can be accomplished using overloading. Am I making any sense? ----- Original Message ----- From: <cron@odi.com.br> To: <php-general@lists.php.net> Sent: Thursday, November 10, 2005 6:47 PM Subject: Re: [PHP] PHP 5 && OO && performance && exceptionsI was not considering that, I was using $obj_string->getValue(), the __toString method and type casting could save me some keystrokes :) Anyway, did you abandon the development with the basic types class? Angelo ----- Original Message ----- From: "Jake Gardner" <gardner.jake@gmail.com> To: <cron@odi.com.br> Sent: Wednesday, November 09, 2005 1:37 PM Subject: Re: [PHP] PHP 5 && OO && performance && exceptions I myself was considering creating classes such as String, but I ran into more basic problems before performance, for example: class String {http://us2.php.net/manual/en/language.types.type-juggling.php#language.types.typecastingprotected $Value; function __construct($Value) { $this->Value = $Value; }} $SomeString = new String("Hello World!"); Print($SomeString); // Does not print "Hello World!" The way around this was still unsatisfactory: class String {protected $Value; function __construct($Value) { $this-> Value = $Value; } function __toString() { return $this->Value; }} $SomeString = new String("Hello World!"); Print($SomeString); // Prints "Hello World!" Because this has obvious limitations, and is only a fix for strings; this doesnt work for functions that expect integer values. In reality, there really is no way to use PHP to rewrite a type in PHP without using the PHP "omni-type". However, you can use type casting as it is:http://us2.php.net/manual/en/function.settype.php On 11/9/05, cron@odi.com.br <cron@odi.com.br> wrote:toHello, Currently I'm make some utilities classes and I took the idea from javatomake some wrappers class like String, Integer and so on. This allows mereplacinguse the type hint for basic types in php. Anyone have a clue ifperformance?the all in one type in php for objects types will degrade theexceptionsAlso for every controller class that I'm making I'm also makingerrorclass of every error that it can generate. Same questions: It will degrade performance to throw an exception instead of lest say a pearor return false? Just for know, I'm doing this because I believe that it will eliminate some o problems o development and will eliminate some basic validations. Any tips appreciate Angelo-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php