Copy link to clipboard
Copied
I'm useed to object orientated programming (C#) so now I'n switching to php its time to write classes. But there's something I don't get in the following code:
<?php
Class path{
private $serverPath;
function _construct()
{
$this->serverPath = $_SERVER['DOCUMENT_ROOT'];
}
public function getServerpath()
{
return $this->serverPath;
}
public function rel2abs ($relpath)
{
if (substr($relpath,0) != "/") $relpath = "/".$relpath;
$relpath = $this->serverPath .$relpath;
return realpath($relpath);
}
}
?>
After debugging it appears that after the object is constructed the private value $serverPath remains NULL ?
M.R.Biesheuvel wrote:
After debugging it appears that after the object is constructed the private value $serverPath remains NULL ?
That's because of an error in your code. The constructor method in a PHP class begins with TWO underscores.
function __construct()
In your code, there's only one underscore.
Copy link to clipboard
Copied
M.R.Biesheuvel wrote:
After debugging it appears that after the object is constructed the private value $serverPath remains NULL ?
That's because of an error in your code. The constructor method in a PHP class begins with TWO underscores.
function __construct()
In your code, there's only one underscore.
Copy link to clipboard
Copied
Thanks, I did not see it in the examples i took __ for _