Re: feature proposal: string types (complete with a patch)
| From: | derick@php.net | Date: | Thu, 02 May 2002 07:13:39 +0000 |
| Subject: | Re: feature proposal: string types (complete with a patch) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-83588@lists.php.net to get a copy of this message | ||
On 2 May 2002, Stig S. Bakken wrote:
<snip>
> I guess the core issue here is whether adding an int to zval or
> zval.value.str is worth the cost. With all the zval copying going on,
> there will be a cpu overhead as well as memory. Back when Andi moved
> zval.value.strlen and zval.value.strval into the str struct, thus saving
> 4 bytes in the zval struct, PHP 3 was generally speeded up by 25%. Not
> sure if the PHP 4 or PHP 5 overhead will be in the same ballpark, but
> it's something to think about.
IMO we should not consider this if it impacts performance even 10% (this
is an arbitrary number. One of the strengths is the speed and I don't want
to lose this.
> IMHO the syntax you suggest is a bit terse, what about this instead:
>
> echo url"http://$host:$port/$path";
Looks perlish to me, I'd rather see a casting thing like this then:
echo (url) "http://$host:$port/$path";
but then you just could make it a function (or a language construct):
echo url("http://$host:$port/$path");
but this can break BC as those functions may be in use in scripts.
<snip>
> But I would like to extend the idea beyond reformatting inserted
> strings. For example, for easy soap/xmlrpc serialization, being able to
> tag a value as a date or some other soap/xmlrpc-specific type is very
> useful.
It might, but remember that PHP is not a strong typed language; somehow it
feels like this is not just PHP then.
Derick
> On Thu, 2002-05-02 at 06:18, vdhome@idas.cz wrote:
> > Dear PHP developers,
> >
> > I propose a feature that I call "string types". I have also already
> > coded a first version of it that you can try. There's a bug for it
> > here: http://bugs.php.net/?id=16480 and a homepage with a
> > description
> > and a patch here:
> > http://nebuchadnezzar.zion.cz/php_strings.php
> > Please be patient when downloading. The server is behind a 64k line.
> > :-(
> >
> > About the feature: It introduces five types of strings: plain string,
> > SQL string, HTML string, URL (query) string and undefined (unknown
> > type) string. The difference is in escaping characters that have
> > special meaning in SQL (quotes, nul), HTML (ampersand, less-than,
> > greater-than, double-quote) and URL (nearly everything except plain
> > letters and digits). The conversion is done automatically when
> > requested. This language extension is fully backwards-compatible;
> > users who don't know about the new features (or don't want to know)
> > need not worry: their existing scripts should work the same without
> > any change. For users who do know about this and want to use it, I
> > believe this new feature should bring significant improvement of code
> > readability, reduction of code size and reduced probability of bugs.
> >
> > I think that the best explanation is by example, so see this:
> >
> > $data = p"a string with 'apostrophes', \"double-quotes\"
> > etc.";
> > mysql_query(s"INSERT INTO table VALUES ('$data')");
> >
> > Because we include a plain string in an SQL string, the plain string
> > is automatically converted to an SQL string, i.e. AddSlashes is
> > applied to it. Strings from GET/POST/COOKIE have the right type,
> > which makes it possible to easily write scripts that do not depend on
> > the setting of magic_quotes_gpc. (An SQL string included in another
> > SQL string is not converted, of course.)
> >
> > Another one:
> >
> > $data = p"a string with <less-than, >greater-than, &ersand";
> > echo h"<INPUT TYPE=HIDDEN NAME=parameter VALUE=\"$data\">";
> >
> > Here, the $data string is automatically HtmlSpecialChars'ed when
> > included in a HTML string.
> >
> > Read more about it on the above mentioned homepage. Try it, test it,
> > tell me what you think about it! Just remember that this is alpha
> > code, and it is very little tested. I make no guarantees whatsoever,
> > except that it has bugs. :-)
> >
> > Please cc me in any replies. I am not subscribed to the list (so in
> > fact, I don't know if it will allow me to post this). I realize that
> > this is not a good practice, but I couldn't handle the loads of mail -
> > and according to http://www.php.net/mailing-lists.php
> > this list
> > isn't available in digest form. :-(
> >
> > Thanks for your attention.
> >
> > Vaclav Dvorak (vdhome@idas.cz)
> > http://nebuchadnezzar.zion.cz/
> >
> > --
> > PHP Development Mailing List <http://www.php.net/>
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php
>
-----------------------------------------------------------------------
Did I help you? Consider a gift:
http://www.amazon.co.uk/exec/obidos/registry/SLCB276UZU8B
-----------------------------------------------------------------------
PHP: Scripting the Web - derick@php.net
All your branches are belong to me!
SRM: Script Running Machine - www.vl-srm.net
-----------------------------------------------------------------------