Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7434

Re: adding a method to a built-in class ?

Message-ID <3288477.yfRR5QZLSb@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-11-02 20:27 +0100
Subject Re: adding a method to a built-in class ?
Newsgroups comp.lang.php
References <508fc27f$0$1948$426a74cc@news.free.fr> <k6qtdk$79q$1@dont-email.me>
Followup-To comp.lang.php

Followups directed to: comp.lang.php

Show all headers | View raw


Gregor Kofler wrote:

> Am 2012-10-30 13:05, Une Bévue meinte:
> > newbie to php5, i'd like to know if i could add a method to a built-in
> > class.
> >
> > The purpose is to ass #to_sql() method to the String class.
> >
> > #to_sql() would just replace any oiccurence of the character "'" by two
> > of it "''".
> 
> There is no such thing as a "string class" in PHP (apart from an
> experimental SplString class). However, you can extend the already
> mentioned Mysqli and Pdo classes and create subclasses tailored to your
> needs.

However, in this particular case that would be unwise, because that user-
defined to_sql() method would hardly be sufficient to escape string values 
in SQL statements safely, and it would most likely be unnecessary to write 
in the first place.

The OP should look into mysql_real_escape_string() if they have to use the 
`mysql' extension, or learn about Prepared Statements (PS) if they can use 
the `mysqli' extension or PDO, instead.  A solution with PS is strongly 
recommended.


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

adding a method to a built-in class ? Une Bévue <unbewusst.sein@fai.invalid> - 2012-10-30 13:05 +0100
  Re: adding a method to a built-in class ? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-10-30 13:38 +0100
    Re: adding a method to a built-in class ? Une Bévue <unbewusst.sein@fai.invalid> - 2012-10-30 14:42 +0100
  Re: adding a method to a built-in class ? Gregor Kofler <usenet@gregorkofler.com> - 2012-10-31 11:09 +0100
    Re: adding a method to a built-in class ? Une Bévue <unbewusst.sein@fai.invalid> - 2012-10-31 15:08 +0100
    Re: adding a method to a built-in class ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-02 20:27 +0100

csiph-web