<?php
class printname
{
var $name;
function show_name()
{
echo "\n";
echo "the name passed to this method is $name.", "\n";
}
}
$obj = new printname;
$obj -> name="alicecheng";
$obj -> show_name();
?>
网页显示:
Notice: Undefined variable: name in f:\php\index.php on line 8
the name passed to this method is .
兔兔写的,可以显示the name passed to this method is alicecheng .
[code:1]
<?php
class Printname
{
var $classname = "Printname";
var $name;
function show_name($name = "") {
echo "\n";
echo "the name passed to this method is $name .\n";
}
}