Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51795 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3213 invoked from network); 2 Apr 2011 16:58:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Apr 2011 16:58:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=martinscotta@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=martinscotta@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: martinscotta@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:48090] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/D1-23967-0C5579D4 for ; Sat, 02 Apr 2011 11:58:41 -0500 Received: by vxb40 with SMTP id 40so3790045vxb.29 for ; Sat, 02 Apr 2011 09:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=xByVV3ujey5T7QB/H1srTasXsLvYAFLSLWlMNx4MS7U=; b=scvi0NLJlWeEgZX2eoeiRO8bXzVHW/7RGxzSDP/lY59eWpQBZBps9PuVAapcjV66yx wIwkgvUMFj9Mm89EnM0AdpyZZaF3MdulLS1oE4WXVxVy5aaFGl8SKdSrZjxQLHoTMgzq KzgQg7G2+ZclunDuSFoyDq2/B95VONKgQW0Wg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=cbtzhnO99EAEHhWHALZbH5No+iBZf4JvONOQ88KNKmUv8G1AchTjsfVuLmu7tA59+B dxkFXn2xAycEiu60LCLeI+bzBP7m1Fu2wSeAbK3XOxzY7hk9btV+dYU/Iah/3z2/9emO duFwPd5dSJRbT/RNwcd7XRNwaWlRfs6U0bt+0= MIME-Version: 1.0 Received: by 10.52.71.228 with SMTP id y4mr2095723vdu.28.1301763516438; Sat, 02 Apr 2011 09:58:36 -0700 (PDT) Received: by 10.220.176.199 with HTTP; Sat, 2 Apr 2011 09:58:35 -0700 (PDT) In-Reply-To: <57CF4B6187F84C31884CE0F70F8F70E2@pc> References: <4D92CC38.5040900@toolpark.com> <004301cbeee8$e54a8280$afdf8780$@com> <4D9387BE.4030808@divbyzero.net> <4D94984D.8060700@lerdorf.com> <4D94A111.7050501@moonspot.net> <520FB834-2614-4873-AC3B-0B2594B18471@roshambo.org> <4D94A350.70201@lerdorf.com> <4D94C380.2070402@lerdorf.com> <57CF4B6187F84C31884CE0F70F8F70E2@pc> Date: Sat, 2 Apr 2011 13:58:35 -0300 Message-ID: To: Stan Vass Cc: Rasmus Lerdorf , internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf307d0436fa9791049ff26fd5 Subject: Re: [PHP-DEV] Adding a more logical string slicing function to PHP From: martinscotta@gmail.com (Martin Scotta) --20cf307d0436fa9791049ff26fd5 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Apr 2, 2011 at 12:41 PM, Stan Vass wrote: > This is actually something I have been toying with a bit. Adding the >> ability to call methods on both strings and arrays. I still don't like >> the idea of making them real objects as the overhead and the amount of >> code that would need to be changed in the core and in every extension is >> daunting. Anybody out there have a patch along these lines? >> >> -Rasmus >> > > > Glad to see pseudo-object methods for scalars/arrays brought up again. > It'll improve workflow a lot. I want to ask/suggest two clarifications on > this: > > 1) You said 'strings and arrays', I hope that's 'scalars and arrays'. As > the current PHP semantics work, and with very minor exceptions, int/float > works as a numeric string when passed to a string function, and numeric > strings work when passed to a number function. > > I.e. those should work: > > $a = 1234; /* int */ echo $a->substr(1); // '234' > $a = '1.23456'; /* string */ $a->format(2); // '1.23' > > This means the extension methods for primitives should be split in two > groups: > > arrays (lists and maps) - one API set > scalars (bool, int, float, strings) - one API set > > 2) Because the language currently has no scalar hinting (I know it's > coming), IDE autocompletion of the extension methods may not work very well > (unless the IDE assumes everything is a scalar unless hinted otherwise). > > Both hinting, incl. for method/function return types, and extension methods > should be introduced together as they make each other more useful, than > independently. > > Let me know what you think. > > Stan Vass > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > What about a marker interface hierarchy like this? interface Mixed { } interface Numeric { } interface Callable extends Mixed { } interface Resource extends Mixed { } interface Scalar extends Mixed { } interface Array extends Mixed { } // unexpected T_ARRAY interface Object extends Mixed { } interface Boolean extends Scalar { } interface String extends Scalar, Numeric { } interface Number extends Scalar, Numeric { } interface Float extends Number { } interface Integer extends Number { } ( http://graph.gafol.net/etSevVPSJ ) This way the core will know which methods are allowed to call on each $var Advantages: * cannnot create instances * cannot extends these interfaces (private to core) * very very fine type hint * core implementation is not exposed Martin Scotta --20cf307d0436fa9791049ff26fd5--