| | |
How to clone a string?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
I have a reference to some string. I need to copy (clone) that string.
This is what I tried
If anyone knows how to do this, please help!
Thanks
This is what I tried
PHP Syntax (Toggle Plain Text)
$newString = $refToString; //this just copies the ref - no new memory allocated $newString = clone $refToString; //this creates "__clone method called on non-object" error
Thanks
•
•
•
•
I have a reference to some string. I need to copy (clone) that string.
This is what I tried
If anyone knows how to do this, please help!PHP Syntax (Toggle Plain Text)
$newString = $refToString; //this just copies the ref - no new memory allocated $newString = clone $refToString; //this creates "__clone method called on non-object" error
Thanks
Try:
php Syntax (Toggle Plain Text)
$str = "joe"; $str2 = $str; $str2 .= " blo"; // you have cloned $str to $str2 by modifying $str2 echo $str; // would give you: joe
I'm sure this holds for all PHP versions to date since strings are "basic" types.
Objects are referenced however in PHP5 and above. PHP4 Objects are referenced on assignment. But cloned on modification.
Last edited by digital-ether; Nov 9th, 2008 at 9:29 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Help me with my myspace clone (PHP)
- Gets all information in listView into a binary file/String variables/textBox in VC++ (C++)
- encrypt and decrypt query string (VB.NET)
- hi.. string compare (Java)
- Printing problems (C#)
- Pls help me (Java)
- help needed with two methods - Dates (Java)
- When a host says "included scripts" (Networking Hardware Configuration)
- My "if" is not good (C)
Other Threads in the PHP Forum
- Previous Thread: Image resize in php
- Next Thread: Need help parsing strings w/ plain text and drop down lists
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube






