Why PHP class does not return <h1>404</h1><p>Not found</p>
?
class checkid{
public $title;
public $content;
function status(){
$this->title='404';
$this->content='Not found';
}
}
$checkid=new checkid($url);
//$id=0;
((isset($id)) ? '' : $checkid->status().$title=开发者_高级运维$checkid->title.$content=$checkid->content);
//Why it does not return `<h1>404</h1><p>Not found</p>`?
echo "<h1>$title</h1><p>$content</p>";
Update: I know well to do it trough
if(isset($id)){}else{
$checkid->status();
$title=$checkid->title;
$content=$checkid->content);
}
but I was worndering if it is possible to make it trough using
((isset($id)) ? '' : $checkid->status().$title=$checkid->title/*here $content break it down*//*.$content=$checkid->content*/);
Change
isset('id')
toisset($id)
.The reason why you were getting
<h1>404Not found</h1><p>Not found</p>
was because you were concatenating the value of$content
to the value of$title
.
Also, you're code is quite a mess. I took the liberty of cleaning it up a bit:
class checkid
{
public $title;
public $content;
function status()
{
$this->title='404';
$this->content='Not found';
}
}
$checkid=new checkid($url);
//$id=0;
if(!isset($id))
{
$checkid->status();
$title=$checkid->title;
$content=$checkid->content;
}
echo "<h1>$title</h1><p>$content</p>";
You don't assign $title
and $content
You probably want something like this
$checkid->status();
echo "<h1>$checkid->title</h1><p>$checkid->content</p>";
Because you are trying to (ab)use a conditional expression as a if statement.
if(!isset($id))
{
$checkid->status();
$title = $checkid->title;
$content = $checkid->content;
}
What isset('id')
means? do you mean isset($id)
or isset($_GET['id'])
?
And, btw,
$checkid->status().$title=$checkid->title.$content=$checkid->content);
is nonsens: you attach the return of status() to $checkid
AND YOU ATTACH $title
which is made equal to $checkid->title
CONCATENATED to $content,
and everythin is assigned $checkid->content
A bit confusing there
精彩评论