FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » adding a method to a built-in class ?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: adding a method to a built-in class ? [message #179503 is a reply to message #179474] Fri, 02 November 2012 19:27 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How do I turn on graphics (GD2) on a Windows 7 system?
Next Topic: Output status during processing
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Dec 20 08:11:06 GMT 2024

Total time taken to generate the page: 0.04226 seconds