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 PHP: How to pass a variable in a function of a class?

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 02-28-2008, 04:16 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: May 2007
Posts: 29
epamnp is an unknown quantity at this point
 



Help! PHP: How to pass a variable in a function of a class?


I have a variable $my_var and I want to pass it in the function Disp(). What is the way to do it?
????: NamePros.com http://www.namepros.com/programming/438389-php-how-pass-variable-function-class.html

<?php
class Page
{
public function __set($name, $value)
{
$this->$name=$value;
}
public function Disp()
{
echo "My first Page" ;
}
}
?>

<?php
$my_var = 'this is a msg' ; // I want to pass this variable in function Disp()
class NextPage extends Page
{
public function Disp()
{
echo $my_var ; // I want to pass the variable $my_var here
}
}
$np = new NextPage();
$np->Disp();
?>
epamnp is offline  
Old 02-28-2008, 04:25 PM   #2 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




PHP Code:
<?php 
$my_var 
'this is a msg' // I want to pass this variable in function Disp()

class NextPage extends Page
     
{
          public function 
Disp($foo)
????: NamePros.com http://www.namepros.com/showthread.php?t=438389
               {
                    echo 
$foo// I want to pass the variable $my_var here
               
}
     }

$np = new NextPage();
$np->Disp($my_var);
?>
Barrucadu is offline  
Old 02-28-2008, 04:46 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: May 2007
Posts: 29
epamnp is an unknown quantity at this point
 



Thank you Mikor.
Last edited by epamnp; 03-02-2008 at 02:33 AM.
epamnp is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:00 AM.

Managed Web Hosting by Liquid Web
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