Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7138 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14555 invoked by uid 1010); 16 Jan 2004 19:58:12 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 14520 invoked from network); 16 Jan 2004 19:58:12 -0000 Received: from unknown (HELO miranda.org) (209.58.150.153) by pb1.pair.com with SMTP; 16 Jan 2004 19:58:12 -0000 Received: (qmail 7429 invoked by uid 546); 16 Jan 2004 19:58:11 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 16 Jan 2004 19:58:11 -0000 Date: Fri, 16 Jan 2004 14:58:11 -0500 (EST) X-X-Sender: adam@miranda.org To: internals@lists.php.net In-Reply-To: Message-ID: References: <132109560218.20040115204833@marcus-boerger.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] __toString() with strval() and settype() From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) Anyone else care to chime in here? If we're really moving to RC1, I think it makes sense to lock down as many language-level features as soon as possible. -adam On Thu, 15 Jan 2004, Adam Maccabee Trachtenberg wrote: > On Thu, 15 Jan 2004, Marcus Boerger wrote: > > Marcus -- > > > Thursday, January 15, 2004, 7:04:09 PM, you wrote: > > > > > > Given an object, $obj, should strval($obj) and settype($obj, 'string') > > > return $obj->__toString() if it exists? > > > > > They currently do not, but (string) $obj does. > > > > > Are these three operations supposed to be identical, but with > > > different syntax? Or are there other differences among them? > > > > Looking at the docs i found this: > > Converting to string > > You can convert a value to a string using the (string) cast, or the > > strval() function. String conversion is automatically done in the scope > > of an expression for you where a string is needed. This happens when > > you use the echo() or print() functions, or when you compare a variable > > value to a string. Reading the manual sections on Types and Type Juggling > > will make the following clearer. See also settype(). > > > > That means strval($x) is equal to (string)$x. > > That's how I believe it. I see (string) as the way people who know C > cast variables in PHP and strval() as the way non-C programmers cast > stuff. :) > > Later on down on that page, it stays that you can't take a strval() of > an object, but I think that's only because before __toString() there > was no meaningful way to handle this. > > > Looking at settype() i found this: > > bool settype ( mixed var, string type) > > Set the type of variable var to type. > > [...] > > See also gettype(), type-casting and type-juggling. > > > > That does not sound like typecasting but it dosn't sound like no > > typecasting being involved too. In other words it is unclear. > > I had always considered settype() to be a generic version of strval(), > intval(), etc. But maybe it's not. > > > So i'd go for strval() calling __tostring() and hearing some other meanings > > on settype(). > > I would like it if strval() called __toString() and I think it also > makes sense for settype() to work this way, but maybe it would be good > to hear from others, in particular maybe the someone who added these > functions? > > -adam > > -- adam@trachtenberg.com author of o'reilly's php cookbook avoid the holiday rush, buy your copy today!