Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7131 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61841 invoked by uid 1010); 15 Jan 2004 19:50:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 61807 invoked from network); 15 Jan 2004 19:50:34 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 15 Jan 2004 19:50:34 -0000 Received: from [192.168.1.100] (p508EB219.dip.t-dialin.net [80.142.178.25]) by shiva.mind.de (Postfix) with ESMTP id 42CA097B66; Thu, 15 Jan 2004 20:50:28 +0100 (CET) Date: Thu, 15 Jan 2004 20:48:33 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <132109560218.20040115204833@marcus-boerger.de> To: Adam Maccabee Trachtenberg Cc: internals@lists.php.net In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] __toString() with strval() and settype() From: helly@php.net (Marcus Boerger) Hello Adam, Thursday, January 15, 2004, 7:04:09 PM, you wrote: > Question: > 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. 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. Looking at TypeJuggling i found: If you wish to force a variable to be evaluated as a certain type, see the section on Type casting. If you wish to change the type of a variable, see settype(). This sounds more like no typecasting but like a string representation. Which could be result of __toString() as well as a text like 'object of type ...' or somthing similar. So i'd go for strval() calling __tostring() and hearing some other meanings on settype(). -- Best regards, Marcus mailto:helly@php.net