hi, am in learning phase of php , am struck here , i try to call method in a class from other class namely display.phtml and displaycall.phtml
i was successfull in calling the method but problem is , i have a variable $_productCode with value equal to 'A1001'. The main part of this problem is the $_productCode variable is outside the class display, under this circumstances , its value is not available inside the class , so if i run the displaycall.phtml , it neglect the $_productCode part of display ,becoz it did not get the value of $_productCode .
Is there any way to acheive it , please help me out. following are the files of code.
display.phtml
<?php
$_productCode = 'A1001';
class display
{
var $itemvalue;
var $_productCode ;
function getData()
{
$itemvalue = $_productCode ;
echo $itemvalue ;
echo "***********";
}
}
$display = new display();
$display->getData();
?>
displaycall.phtml
<?php
include "display.phtml";
class displaycall extends display
{
public function printItem($string)
{
echo 'displaycall: ' . $string . '';
}
}
$display = new display();
$displaycall = new displaycall();
// Output: 'display: baz'
// Output: 'PHP is great'
$displaycall->printItem('baz'); // Output: 'Bar: baz'
// Output: 'PHP is great'
?>