I'm trying to use PHP_SELF in a class but it isn't working. I have two files:
classtest.php
page.inc
In classtest.php I create a new web page using the Page class which is defined in page.inc. In page.inc I have a function SetFilename() that gets the basename of the file (I found this function here on ee). Previously, I was using this function directly in a php script file that created a web page (without the use of a class) and it worked. It isn't working using a class.
The value I'm trying to get for the $this->filename variable is: classtest
I anticipated a problem with this but thought that I just might get the wrong value for $this->filename(page from page.inc). But I'm not getting anything.
classtest.php
--------------
<?php
require('page.inc');
$classtestpage = new Page();
$classtestpage -> Display();
?>
page.inc
---------
<?php
class Page
{
//class Page's attributes
var $content;
var $title = 'Test Title';
var $keywords = 'Test Keyword, Test Keyword 2';
var $filename;
//class Page's operations
function SetFilename()
{
$brk_filename = explode(".", basename($PHP_SELF));
$num_part = count($brk_filename);
if( $num_part >1)
unset($brk_filename[$num_p
art-1]);
$this->filename = implode(".", $brk_filename);
}
function Display()
{
echo "<html>\n<head>\n";
$this->DisplayTitle();
$this->DisplayKeywords();
echo "</head>\n<body>\n";
$this->DisplayFilename();
echo "this is a test from the display function";
echo "</body>\n</html>\n";
}
function DisplayTitle()
{
echo '<title>'.$this->title.'</
title>';
}
function DisplayKeywords()
{
echo "<META name =\"keywords\" content=\"".$this->keyword
s."\">";
}
function DisplayFilename()
{
echo $this->filename;
}
}
?>
Start Free Trial