NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page why this doesn't work? [PHP]

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 09-01-2010, 08:20 AM THREAD STARTER               #1 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




why this doesn't work? [PHP]


PHP Code:
class video
{
    public function 
__construct($text)
    {
    
$this->youtube($text"[*]");
    }

    public function 
youtube($text$code)
    {
        
$html preg_replace("#\[\*\]#"$text$code);
????: NamePros.com http://www.namepros.com/programming/675153-why-this-doesnt-work-php.html

        return 
$html;
    }
}  

$video_class = new video("HELLO");

echo 
$video_class
Can someone explain to me why that gives this error:

Catchable fatal error: Object of class video could not be converted to string in /home/prxainf1/public_html/gamingonlinux.info/test.php on line 21
liam_d is offline   Reply With Quote
Old 09-01-2010, 03:01 PM   #2 (permalink)
NamePros Member
 
un4given[MAD]'s Avatar
Join Date: Aug 2008
Location: Solar System \ Earth \ Ukraine \ Kiev
Posts: 43
un4given[MAD] is on a distinguished road
 



Originally Posted by liam_d View Post
Can someone explain to me why that gives this error:
????: NamePros.com http://www.namepros.com/showthread.php?t=675153
Catchable fatal error: Object of class video could not be converted to string in /home/prxainf1/public_html/gamingonlinux.info/test.php on line 21
I'm sorry to be Captain Obvious, but "echo" is intended to output strings, not objects In your example variable $video_class is an object, so you can't just output it.

Are you familiar with object-oriented programming?
__________________
Tired playing Freecell, Klondike or Spider? Discover 800 solitaire games at SolitairesUnlimited.com and play'em all!
un4given[MAD] is offline   Reply With Quote
Old 09-01-2010, 07:20 PM   #3 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 360
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
This will work:

PHP Code:
class video
{
    protected 
$text;
    protected 
$code;

    public function 
__construct($text,$code="[*]")
    {
        
$this->text $text;
        
$this->code $code;
    }

    public function 
__toString()
????: NamePros.com http://www.namepros.com/showthread.php?t=675153
    {
        
$html preg_replace("#\[\*\]#"$this->text$this->code);

        return 
$html;
    }
}  

$video_class = new video("HELLO");

echo 
$video_class
Reference PHP: Magic Methods - Manual
__________________
Canadian Domain Registrar Ready.ca
baxter is offline   Reply With Quote
Old 09-26-2010, 09:27 PM   #4 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,615
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 




Or this should work

PHP Code:
<?php
class video
{
    public function 
__construct()
    {
    }

    public function 
youtube($text$code)
????: NamePros.com http://www.namepros.com/showthread.php?t=675153
    {
        
$html preg_replace("#\[\*\]#"$text$code);

        return 
$html;
    }
}  

$video_class = new video();
echo 
$video_class->youtube('HELLO'"[*]");
?>
__________________
xrvel is offline   Reply With Quote
Old 10-15-2010, 02:40 PM   #5 (permalink)
NamePros Member
Join Date: Feb 2010
Posts: 99
digital29 is an unknown quantity at this point
 



Use var_dump to display objects
digital29 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:37 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger