I was wondering if anyone can comment on this idea
cause I think it would be a great asset to PHP and to OOP in PHP..
example:
$b = 4;
$a = new Integer(4);
if($a == $b) {
//bla bla
}
Other classes would include String(), Integer(), Boolean() ... and so on...
Hello Ante,
autoboxing is an ugly java 1.5 workarount to enable storage of base
tyoes in containers. There this trick is necessary because as always
in java everything must be an 'Object'. In contrast PHP is a loosly
typed language where a container aka array can store any type. Apart
from that as with java there is no user space enabled way to implement
such autoboxing types and even the java way of building it into the
engine is not supported and won't be.
regards
marcus
Monday, February 7, 2005, 3:21:59 PM, you wrote:
I was wondering if anyone can comment on this idea
cause I think it would be a great asset to PHP and to OOP in PHP..
example:
$b = 4;
$a = new Integer(4);
if($a == $b) {
//bla bla
}
Other classes would include String(), Integer(), Boolean() ... and so on...
--
Best regards,
Marcus mailto:helly@php.net
Hi Marcus and thanx for the explanation....
And I agree that PHP is very loose which is his strong part but
exactly because of that I think it would be nice if the end-user can have
the ability to work with primitives like they were objects...
I didn't want to suggest that PHP should implement Autoboxing as JAVA
but I did like the concept of having objects for primitive types....
Marcus Boerger wrote:
Hello Ante,
autoboxing is an ugly java 1.5 workarount to enable storage of base
tyoes in containers. There this trick is necessary because as always
in java everything must be an 'Object'. In contrast PHP is a loosly
typed language where a container aka array can store any type. Apart
from that as with java there is no user space enabled way to implement
such autoboxing types and even the java way of building it into the
engine is not supported and won't be.regards
marcusMonday, February 7, 2005, 3:21:59 PM, you wrote:
I was wondering if anyone can comment on this idea
cause I think it would be a great asset to PHP and to OOP in PHP..example:
$b = 4;
$a = new Integer(4);if($a == $b) {
//bla bla
}Other classes would include String(), Integer(), Boolean() ... and so on...
Hi Marcus and thanx for the explanation....
And I agree that PHP is very loose which is his strong part but
exactly because of that I think it would be nice if the end-user can have
the ability to work with primitives like they were objects...
Why?
- Andrei
Andrei Zmievski wrote:
Hi Marcus and thanx for the explanation....
And I agree that PHP is very loose which is his strong part but
exactly because of that I think it would be nice if the end-user can have
the ability to work with primitives like they were objects...Why?
- Andrei
Why not?
Because it would be a great asset to the new OOP model in PHP 5....
Because the new OOP model is great and I don't think it shouldn't stop
there....
Because it would be great if the choice is left to the end user...
We already have OOP freaks (including this one) and I just love the idea
to have something like
function Add($a, $b) {
return new Float($a+$b);
}
print(Add(new Integer(5), new Float(5.7)));
just my $.02
Man, that's the primary reason I don't like Java :)
You can't be serious :)
Ron
"Ante Drnasin" ante.dfg@moj.net wrote in message
news:20050210080546.52065.qmail@lists.php.net...
Andrei Zmievski wrote:
Hi Marcus and thanx for the explanation....
And I agree that PHP is very loose which is his strong part but
exactly because of that I think it would be nice if the end-user can
have
the ability to work with primitives like they were objects...Why?
- Andrei
Why not?
Because it would be a great asset to the new OOP model in PHP 5....
Because the new OOP model is great and I don't think it shouldn't stop
there....
Because it would be great if the choice is left to the end user...We already have OOP freaks (including this one) and I just love the idea
to have something likefunction Add($a, $b) {
return new Float($a+$b);
}print(Add(new Integer(5), new Float(5.7)));
just my $.02
Andrei Zmievski wrote:
Hi Marcus and thanx for the explanation....
And I agree that PHP is very loose which is his strong part but
exactly because of that I think it would be nice if the end-user can have
the ability to work with primitives like they were objects...Why?
- Andrei
Why not?
Because it would be a great asset to the new OOP model in PHP 5....
Because the new OOP model is great and I don't think it shouldn't stop
there....
Because it would be great if the choice is left to the end user...
But there is no good reason why we should add this.
We already have OOP freaks (including this one) and I just love the idea
to have something likefunction Add($a, $b) {
return new Float($a+$b);
}
function add($a, $b) {
return (float)($a + $b);
}
nothing new to add here...
Derick
--
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org
Why?
- Andrei
Why not?
Because it would be a great asset to the new OOP model in PHP 5....
You did't answer my question. Why?
Because the new OOP model is great and I don't think it shouldn't stop
there....
Why?
Because it would be great if the choice is left to the end user...
Why?
We already have OOP freaks (including this one) and I just love the idea
to have something likefunction Add($a, $b) {
return new Float($a+$b);
}
Why?
print(Add(new Integer(5), new Float(5.7)));
Why?
- Andrei
You did't answer my question. Why?
I am def. a fan of this idea. I'd love to see internally a set of
Java-style objects representing the basic types in PHP.
As for why I have two reasons:
Although PHP is not a strongly-typed language and never will be, with
the introduction of type-hinting I feel that having a standard set of
objects representing the fundamental types in PHP will allow developers
of libraries to enforce the proper restrictions if they desire on the
types which end up in their functions. This further degree of control
over the architecture in a PHP class makes an architecture tighter and
easier to manage with growth.
More importantly than the concept of type-hinting, the lack of typing
information is holding PHP back signifcantly in the realm of Web
Services. Although for PHP applications as a whole typing has proven
itself largely unnecessary, without it making PHP a viable and "simple"
language for the creation of web services isn't feasible. How am I to
create a WSDL document from a class I would like to expose as a web
service? Do you honestly expect me to hand-write a WSDL document for my
object and maintain that WSDL alongside code changes manually? WSDL
documents were designed to be generated automatically by the
architecture exposing the web service, and without any notion of typing
in PHP at all there is no viable way to really do this.
Also let me point out that I am not suggesting that PHP become a typed
language. I am merely am suggesting that the ability for me to enforce
structure on my objects does indeed have a real benefit without breaking
backward compatibility or otherwise compromising the spirit of PHP.
John
To be clear:
Although I think this might be implemented as some sort of object I am
not interested in making objects out of everything. All I want is this:
function foo(Integer $a, Float $b, String $c, Boolean $d) {
}
and be able to introspect against that... how that ultimately gets
implemented (likely PHP would auto-cast that to an int) doesn't matter
to me... but the point here is I think the ability to have more
optional meta-data associated with function declarations shouldn't be
brushed off as nonsense when there are real benefits to the ability.
John
You did't answer my question. Why?
I am def. a fan of this idea. I'd love to see internally a set of
Java-style objects representing the basic types in PHP.As for why I have two reasons:
Although PHP is not a strongly-typed language and never will be, with
the introduction of type-hinting I feel that having a standard set of
objects representing the fundamental types in PHP will allow developers
of libraries to enforce the proper restrictions if they desire on the
types which end up in their functions. This further degree of control
over the architecture in a PHP class makes an architecture tighter and
easier to manage with growth.More importantly than the concept of type-hinting, the lack of typing
information is holding PHP back signifcantly in the realm of Web
Services. Although for PHP applications as a whole typing has proven
itself largely unnecessary, without it making PHP a viable and "simple"
language for the creation of web services isn't feasible. How am I to
create a WSDL document from a class I would like to expose as a web
service? Do you honestly expect me to hand-write a WSDL document for my
object and maintain that WSDL alongside code changes manually? WSDL
documents were designed to be generated automatically by the
architecture exposing the web service, and without any notion of typing
in PHP at all there is no viable way to really do this.Also let me point out that I am not suggesting that PHP become a typed
language. I am merely am suggesting that the ability for me to enforce
structure on my objects does indeed have a real benefit without breaking
backward compatibility or otherwise compromising the spirit of PHP.John
function foo(Integer $a, Float $b, String $c, Boolean $d) {
}
Having that automagically translate to:
function foo($a, $b, $c, $d) {
set_type($a, 'int');
set_type($b, 'float');
set_type($c, 'string');
set_type($d, 'bool');
}
Is something that I could see building into the language (in all honesty,
isn't that was zend_parse_parameters does for internal functions already?),
but objects for primitives? Didn't someone say something about smelly
corpses recently? maybe it was "charred"? cold? smoking? rank?
-Sara
Is something that I could see building into the language (in all honesty,
isn't that was zend_parse_parameters does for internal functions already?),
but objects for primitives? Didn't someone say something about smelly
corpses recently? maybe it was "charred"? cold? smoking? rank?
I don't want objects for primitives, at least that's not where I was
going. I am only arguing the typehinting of primitives.
John
Is something that I could see building into the language (in all honesty,
isn't that was zend_parse_parameters does for internal functions
already?),
but objects for primitives? Didn't someone say something about smelly
corpses recently? maybe it was "charred"? cold? smoking? rank?I don't want objects for primitives, at least that's not where I was
going. I am only arguing the typehinting of primitives.
Then we agree. Just wanted to remove that edge of doubt.
-Sara
John Coggeshall wrote:
I am only arguing the typehinting of primitives.
I would like to see typehinting for primitives, too.
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
John Coggeshall wrote:
To be clear:
Although I think this might be implemented as some sort of object I am
not interested in making objects out of everything. All I want is this:function foo(Integer $a, Float $b, String $c, Boolean $d) {
}
and be able to introspect against that... how that ultimately gets
implemented (likely PHP would auto-cast that to an int) doesn't matter
to me... but the point here is I think the ability to have more
optional meta-data associated with function declarations shouldn't be
brushed off as nonsense when there are real benefits to the ability.John
You did't answer my question. Why?
I am def. a fan of this idea. I'd love to see internally a set of
Java-style objects representing the basic types in PHP.As for why I have two reasons:
Although PHP is not a strongly-typed language and never will be, with
the introduction of type-hinting I feel that having a standard set of
objects representing the fundamental types in PHP will allow developers
of libraries to enforce the proper restrictions if they desire on the
types which end up in their functions. This further degree of control
over the architecture in a PHP class makes an architecture tighter and
easier to manage with growth.More importantly than the concept of type-hinting, the lack of typing
information is holding PHP back signifcantly in the realm of Web
Services. Although for PHP applications as a whole typing has proven
itself largely unnecessary, without it making PHP a viable and "simple"
language for the creation of web services isn't feasible. How am I to
create a WSDL document from a class I would like to expose as a web
service? Do you honestly expect me to hand-write a WSDL document for my
object and maintain that WSDL alongside code changes manually? WSDL
documents were designed to be generated automatically by the
architecture exposing the web service, and without any notion of typing
in PHP at all there is no viable way to really do this.Also let me point out that I am not suggesting that PHP become a typed
language. I am merely am suggesting that the ability for me to enforce
structure on my objects does indeed have a real benefit without breaking
backward compatibility or otherwise compromising the spirit of PHP.John
Exactly!
John Coggeshall wrote:
object and maintain that WSDL alongside code changes manually? WSDL
documents were designed to be generated automatically by the
architecture exposing the web service, and without any notion of typing
in PHP at all there is no viable way to really do this.
Don't forget about the use of in-code documentation to extract type
information. I wrote an xml-rpc implementation that relies on
reflection and a very small documentation parser to validate incoming
signatures. Davey Shafik took some of his own code and the same ideas
to write a WSDL generator for his Cerebral Cortex project.
The best thing internals could do for WSDL is to add a documentation
lexer to reflection, but I would be surprised if this happens - too
complicated unless it's really crude :)
Greg
The best thing internals could do for WSDL is to add a documentation
lexer to reflection, but I would be surprised if this happens - too
complicated unless it's really crude :)
I did something like this using getDocComment() and preg_match()
for
Services_Ebay. It was really crude. :)
-adam
--
adam@trachtenberg.com | http://www.trachtenberg.com
author of o'reilly's "upgrading to php 5" and "php cookbook"
avoid the holiday rush, buy your copies today!