Re: [PHP-DEV] type hinting

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 23:58 -0300, Martin Alterisio wrote: > A friend told me you were having a most interesting debate on type hinting > in the internals, when I got some free time I checked the newsgroup to see > how was it coming. It's quite interesting and many good points have been > made alre

Re: [PHP-DEV] type hinting

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 23:15 +0100, Stefan Esser wrote: > Hi Marcus, > > That said I would only agree to type hints if we make them respect existing > > PHP conversion rules > if "type hints" are supposed to convert data, then they are wrongly > named. Then they should be better called "implicit typ

Re: [PHP-DEV] type hinting

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 23:15 +0100, Stefan Priebsch wrote: > Pierre schrieb: > > I don't see the point to make a application working when you pass to > > it the wrong data, it is a bad usage. That was the moto for the > > So how are you going to deal with the "bad usage" then? Isn't the > proble

Re: [PHP-DEV] type hinting

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 22:41 +0100, Pierre wrote: > On Jan 6, 2008 9:55 PM, Stefan Priebsch <[EMAIL PROTECTED]> wrote: > > Pierre schrieb: > > > When a method or function uses the strict typing, it is on purpose. It > > > is documented (self documented and hopefully using normal docs). There > > > i

Re: [PHP-DEV] type hinting

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 21:23 +, Alain Williams wrote: > On Sun, Jan 06, 2008 at 10:08:16PM +0100, Markus Fischer wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA1 > > > > Pierre wrote: > > | That can be a good compromise and may make happy the cons camp. > > | However, I would not li

Re: [PHP-DEV] type hinting

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 21:53 +0100, Pierre wrote: > Hi Marcus, > > On Jan 6, 2008 9:24 PM, Marcus Boerger <[EMAIL PROTECTED]> wrote: > > > That said I would only agree to type hints if we make them respect existing > > PHP conversion rules. > > That can be a good compromise and may make happy the

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 20:02 +, Mikko Koppanen wrote: > > > > Why I mean by: > >Type HINTING is not type ENFORCEMENT. > > is that: > >function foo(int $a) {} > > > >foo(1); // OK > > > >foo("1"); // OK - the string is juggled to an int when the > > f

Re: [PHP-DEV] type hinting

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 15:41 -0300, Cristian Rodriguez wrote: > 2008/1/4, Jani Taskinen <[EMAIL PROTECTED]>: > > > As I'm +1 for OPTIONAL scalar-type hinting. > > me too +1 as long as : > > > function foo(int $a) {} > > foo('5'); > > ?> > > Raises an error, and is rejected because is not a v

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 19:18 +0200, Giedrius D wrote: > On Jan 6, 2008 5:55 PM, Sam Barrow <[EMAIL PROTECTED]> wrote: > > As I said, this patch is not intended for stuff like $_GET, $_POST, > > database data, etc. It is intended for internal functions to your > > application. > > > > function requir

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 09:03 -0800, Mike Lively wrote: > On Sun, 2008-01-06 at 10:55 -0500, Sam Barrow wrote: > > > function requireFile(string $file, bool $getOutput = false, array $args > > // ... > > This function will not be called using input data. > > > > So is there some way you are ensuri

[PHP-DEV] type hinting

2008-01-06 Thread Martin Alterisio
A friend told me you were having a most interesting debate on type hinting in the internals, when I got some free time I checked the newsgroup to see how was it coming. It's quite interesting and many good points have been made already. But it is quite difficult to understand some concepts that som

Re: [PHP-DEV] type hinting

2008-01-06 Thread Pierre
On Jan 7, 2008 12:01 AM, Stefan Priebsch <[EMAIL PROTECTED]> wrote: > Pierre schrieb: > > That what happens now with the numerous fatal errors. That's not the > > case with an E_RECOVERABLE error. PHP has no compiler and all errors > > will be see at runtime, even fatals like missing classes, funct

Re: [PHP-DEV] type hinting

2008-01-06 Thread Stefan Priebsch
Pierre schrieb: That what happens now with the numerous fatal errors. That's not the case with an E_RECOVERABLE error. PHP has no compiler and all errors will be see at runtime, even fatals like missing classes, functions, methods, wrong interfaces or bad usages of set/getters. Sorry, not true.

Re: [PHP-DEV] Source type.c says settype($var, "double") is deprecated

2008-01-06 Thread Markus Fischer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, Hannes Magnusson wrote: | It means that in PHP the type name is 'float' and referred to as | 'float' throughout the manual | For convenience you can use "double" (is_double($f), (double)$f, | settype($f, "double")..), just like you can use is_int

Re: [PHP-DEV] Source type.c says settype($var, "double") is deprecated

2008-01-06 Thread Hannes Magnusson
On Jan 6, 2008 9:23 PM, Markus Fischer <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi, > > Hannes Magnusson wrote: > | No, the comment is correct. > | > | "for historical [read: BC] reasons "double" is returned in case of a > | float, and not simply "float"" > |

Re: [PHP-DEV] type hinting

2008-01-06 Thread Pierre
On Jan 6, 2008 11:15 PM, Stefan Priebsch <[EMAIL PROTECTED]> wrote: > Pierre schrieb: > > I don't see the point to make a application working when you pass to > > it the wrong data, it is a bad usage. That was the moto for the > > So how are you going to deal with the "bad usage" then? > Isn't th

Re: [PHP-DEV] type hinting

2008-01-06 Thread Alain Williams
On Sun, Jan 06, 2008 at 11:15:43PM +0100, Stefan Priebsch wrote: > Pierre schrieb: > > I don't see the point to make a application working when you pass to > > it the wrong data, it is a bad usage. That was the moto for the > > So how are you going to deal with the "bad usage" then? Isn't the > p

Re: [PHP-DEV] type hinting

2008-01-06 Thread Stefan Esser
Hi Marcus, > That said I would only agree to type hints if we make them respect existing > PHP conversion rules if "type hints" are supposed to convert data, then they are wrongly named. Then they should be better called "implicit typecasting". However "implicit typecasting" is not really usefull f

Re: [PHP-DEV] type hinting

2008-01-06 Thread Stefan Priebsch
Pierre schrieb: > I don't see the point to make a application working when you pass to > it the wrong data, it is a bad usage. That was the moto for the So how are you going to deal with the "bad usage" then? Isn't the problem that this "bad usage" is discovered at runtime, vs at compile time l

Re: [PHP-DEV] type hinting

2008-01-06 Thread Pierre
On Jan 6, 2008 10:46 PM, Stefan Priebsch <[EMAIL PROTECTED]> wrote: > Error handling is to catch the exception (or error) and take measures so > that your program can continue to work. I don't see the point to make a application working when you pass to it the wrong data, it is a bad usage. That

Re: [PHP-DEV] type hinting

2008-01-06 Thread Pierre
On Jan 6, 2008 10:48 PM, Marcus Boerger <[EMAIL PROTECTED]> wrote: > Hello Pierre, > > I agree something that is not really a number should not be converted into > a number as it is not compatible but then...what do we do right now? > > [EMAIL PROTECTED] PHP_5_3]$ php -r 'var_dump(fmod(12,5));' >

Re: [PHP-DEV] type hinting

2008-01-06 Thread Marcus Boerger
Hello Pierre, I agree something that is not really a number should not be converted into a number as it is not compatible but then...what do we do right now? [EMAIL PROTECTED] PHP_5_3]$ php -r 'var_dump(fmod(12,5));' make: `sapi/cli/php' is up to date. float(2) [EMAIL PROTECTED] PHP_5_3]$ php -

Re: [PHP-DEV] type hinting

2008-01-06 Thread Alain Williams
On Sun, Jan 06, 2008 at 10:43:19PM +0100, Marcus Boerger wrote: > Hello Johannes, > > then obviously pass by reference and base type hints are not compatible. > Apart from that so far in PHP it does not matter whether a variable changes > in base type. And we should not change this nature of PHP

Re: [PHP-DEV] type hinting

2008-01-06 Thread Stefan Priebsch
Pierre schrieb: Sorry, but I don't understand you. Why is there no need of error handling? I meant in user land, like adding tests and raising exception or an error. I think there is a misunderstanding here: testing and raising exceptions is not error handling to me. This is checking conditi

Re: [PHP-DEV] type hinting

2008-01-06 Thread Marcus Boerger
Hello Johannes, then obviously pass by reference and base type hints are not compatible. Apart from that so far in PHP it does not matter whether a variable changes in base type. And we should not change this nature of PHP. marcus Sunday, January 6, 2008, 10:03:44 PM, you wrote: > Hi, > On

Re: [PHP-DEV] type hinting

2008-01-06 Thread Pierre
On Jan 6, 2008 9:55 PM, Stefan Priebsch <[EMAIL PROTECTED]> wrote: > Pierre schrieb: > > When a method or function uses the strict typing, it is on purpose. It > > is documented (self documented and hopefully using normal docs). There > > is no need of error handling, it is an usage error and shoul

Re: [PHP-DEV] type hinting

2008-01-06 Thread Markus Fischer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Alain Williams wrote: |> Pierre wrote: |> | That can be a good compromise and may make happy the cons camp. |> | However, I would not like to have "11an" returns 0 but raises an |> | error. I can live with "[0-1.]" being converted to integer or float

Re: [PHP-DEV] type hinting

2008-01-06 Thread Alain Williams
On Sun, Jan 06, 2008 at 10:08:16PM +0100, Markus Fischer wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Pierre wrote: > | That can be a good compromise and may make happy the cons camp. > | However, I would not like to have "11an" returns 0 but raises an > | error. I can live with "[

Re: [PHP-DEV] type hinting

2008-01-06 Thread Markus Fischer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Pierre wrote: | That can be a good compromise and may make happy the cons camp. | However, I would not like to have "11an" returns 0 but raises an | error. I can live with "[0-1.]" being converted to integer or float as | it is the case now. Even I wo

Re: [PHP-DEV] type hinting

2008-01-06 Thread Johannes Schlüter
Hi, On Sun, 2008-01-06 at 21:24 +0100, Marcus Boerger wrote: > That said I would only agree to type hints if we make them respect existing > PHP conversion rules. Which we can't really do. Think about Mikko's example: $b = '5'; function foo( int &$a ) { echo gettype( $a ); } foo( $b ); echo

Re: [PHP-DEV] type hinting

2008-01-06 Thread Stefan Priebsch
Pierre schrieb: When a method or function uses the strict typing, it is on purpose. It is documented (self documented and hopefully using normal docs). There is no need of error handling, it is an usage error and should raise a E_{whatever}, be happy, it will not be fatal as it is now in all thes

Re: [PHP-DEV] type hinting

2008-01-06 Thread Pierre
Hi Marcus, On Jan 6, 2008 9:24 PM, Marcus Boerger <[EMAIL PROTECTED]> wrote: > That said I would only agree to type hints if we make them respect existing > PHP conversion rules. That can be a good compromise and may make happy the cons camp. However, I would not like to have "11an" returns 0 bu

Re: [PHP-DEV] type hinting

2008-01-06 Thread Pierre
On Jan 6, 2008 9:37 PM, Stefan Priebsch <[EMAIL PROTECTED]> wrote: > I'm a little afraid that introducing type hints will have us end up with > code like this (to stick with a previous example): > > > function foo(int $a) {} > > foo((int) '5'); > > ?> > > So, just to make sure, add Java-ish typeca

Re: [PHP-DEV] type hinting

2008-01-06 Thread Stefan Priebsch
I'm a little afraid that introducing type hints will have us end up with code like this (to stick with a previous example): So, just to make sure, add Java-ish typecasts everywhere. I'm not sure if that solves the problem (error handling still required when the cast is not possible), but may

Re: [PHP-DEV] type hinting

2008-01-06 Thread Marcus Boerger
Hello Cristian, Sunday, January 6, 2008, 7:42:58 PM, you wrote: > 2008/1/5, Alain Williams <[EMAIL PROTECTED]>: >> "1" and 1 should both be acceptable to type hint 'int'. > No way, "1" is an string, not an integer. Well that is the whole issue here. In PHP "1" is pretty equal to 1 in any funct

Re: [PHP-DEV] Source type.c says settype($var, "double") is deprecated

2008-01-06 Thread Markus Fischer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, Hannes Magnusson wrote: | No, the comment is correct. | | "for historical [read: BC] reasons "double" is returned in case of a | float, and not simply "float"" | | See http://docs.php.net/settype && http://docs.php.net/gettype Thanks for the poi

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Markus Fischer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mikko Koppanen wrote: | I have not been following very closely this conversation so this might have | been answered already: | | | $b = '5'; | | function foo( int &$a ) | { | echo gettype( $a ); | } | | foo( $b ); | | echo gettype( $b ); | | | what

Re: [PHP-DEV] Source type.c says settype($var, "double") is deprecated

2008-01-06 Thread Hannes Magnusson
On Jan 6, 2008 8:37 PM, Markus Fischer <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi, > > accidentally I came across settype() in ext/standard/type.c which says > > ~ } else if (!strcasecmp(new_type, "float")) { > ~convert_to_double(*var); > ~ } else if (

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Mikko Koppanen
> > Why I mean by: >Type HINTING is not type ENFORCEMENT. > is that: >function foo(int $a) {} > >foo(1); // OK > >foo("1"); // OK - the string is juggled to an int when the > function is called >// ENFORCEMENT would have (in some

[PHP-DEV] Source type.c says settype($var, "double") is deprecated

2008-01-06 Thread Markus Fischer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, accidentally I came across settype() in ext/standard/type.c which says ~ } else if (!strcasecmp(new_type, "float")) { ~convert_to_double(*var); ~ } else if (!strcasecmp(new_type, "double")) { /* deprecated */ ~convert_to_double(*var);

Re: [PHP-DEV] type hinting

2008-01-06 Thread Cristian Rodriguez
2008/1/5, Alain Williams <[EMAIL PROTECTED]>: > "1" and 1 should both be acceptable to type hint 'int'. No way, "1" is an string, not an integer. -- http://www.kissofjudas.net/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] type hinting

2008-01-06 Thread Cristian Rodriguez
2008/1/4, Jani Taskinen <[EMAIL PROTECTED]>: > As I'm +1 for OPTIONAL scalar-type hinting. me too +1 as long as : Raises an error, and is rejected because is not a valid integer, otherwise -1 -- http://www.kissofjudas.net/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscr

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Giedrius D
On Jan 6, 2008 5:55 PM, Sam Barrow <[EMAIL PROTECTED]> wrote: > As I said, this patch is not intended for stuff like $_GET, $_POST, > database data, etc. It is intended for internal functions to your > application. > > function requireFile(string $file, bool $getOutput = false, array $args > = arra

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Mike Lively
On Sun, 2008-01-06 at 10:55 -0500, Sam Barrow wrote: > function requireFile(string $file, bool $getOutput = false, array $args > // ... > This function will not be called using input data. > So is there some way you are ensuring that users of your code NEVER pass a value that trickled down from

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 15:59 +0100, Magnus Määttä wrote: > On Sunday 06 January 2008, Alain Williams wrote: > > On Sun, Jan 06, 2008 at 01:02:54PM +0100, Stefan Esser wrote: > > > Hello Alain, > > > > > > I think you are also confused about PHP type hinting... > > > > > > The manual clearly states

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Sam Barrow
On Sun, 2008-01-06 at 11:28 +, Alain Williams wrote: > On Sat, Jan 05, 2008 at 07:34:04PM -0800, Mike Lively wrote: > > > input is going to makes it's way into your api at some point. Now of > > course you can (and should) be filtering this > > input before it is used, but if imo when dealin

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Magnus Määttä
On Sunday 06 January 2008, Alain Williams wrote: > On Sun, Jan 06, 2008 at 01:02:54PM +0100, Stefan Esser wrote: > > Hello Alain, > > > > I think you are also confused about PHP type hinting... > > > > The manual clearly states: > > > > > > > Type Hinting > > > > > PHP 5 introduces Type Hi

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Sven Drieling
Am Sonntag, 6. Januar 2008 12:28 schrieb Alain Williams: Hello, > You are confusing the TYPE and the VALUE. > > What type hinting means is: > > * is the TYPE correct ? If so succeed. > > * can the VALUE be 100% converted to the desired TYPE (eg '5' to int) ? > If so succeed. > > * fail \n"; // =

Re: [PHP-DEV] Re: PATCH: Implementing closures in PHP

2008-01-06 Thread Marcus Boerger
Hello Stanislav, tha makesw three then already, how about we ask around again? Ryusuke, can you please start a new '[RFC] Square brackets shortcut' thread to collect opinions and pass along the patch for that? I like the anonymous function patch too. It is clean and simple. Maybe you want to st

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Alain Williams
On Sun, Jan 06, 2008 at 01:02:54PM +0100, Stefan Esser wrote: > Hello Alain, > > I think you are also confused about PHP type hinting... > > The manual clearly states: > > > > Type Hinting > > > PHP 5 introduces Type Hinting. Functions are now able to force > parameters to be objects (by s

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Stefan Esser
Hello Alain, I think you are also confused about PHP type hinting... The manual clearly states: > Type Hinting > PHP 5 introduces Type Hinting. Functions are now able to force parameters to be objects (by specifying the name of the class in the function prototype) or arrays (since PHP 5.1)

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Alain Williams
On Sun, Jan 06, 2008 at 12:51:20PM +0100, Kore Nordmann wrote: > > Am Sonntag, den 06.01.2008, 11:28 + schrieb Alain Williams: > > PLEASE READ CAREFULLY > > > > You have NOT understood what type hinting is about. > > > > You are confusing the TYPE and the VALUE. > > > > What type hinting me

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Kore Nordmann
Am Sonntag, den 06.01.2008, 11:28 + schrieb Alain Williams: > On Sat, Jan 05, 2008 at 07:34:04PM -0800, Mike Lively wrote: > > > input is going to makes it's way into your api at some point. Now of > > course you can (and should) be filtering this > > input before it is used, but if imo whe

Re: [PHP-DEV] Type hinting misunderstood

2008-01-06 Thread Alain Williams
On Sat, Jan 05, 2008 at 07:34:04PM -0800, Mike Lively wrote: > input is going to makes it's way into your api at some point. Now of course > you can (and should) be filtering this > input before it is used, but if imo when dealing with a loosely typed > language where the same input could be hi

Re: [PHP-DEV] U

2008-01-06 Thread Stefan Esser
Hello Daniel, > It may be off-topic for the initial post, but I disagree > wholeheartedly with the above statement, Stefan. There are > innumerable reasons where $_REQUEST would be much more economic than > writing out all conditions for $_POST, $_GET, $_SESSION, $_COOKIE > it doesn't m