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>";
0 comments:
Post a Comment