I want to have a function which takes 1 parameter as input, if no value is passed it should take default value as another function's output. Am using Class in PHP to achieve this but it's giving me error as "Constant expression contains invalid operations"
<?php
class Common
{
public $usrname;
function getLoggedInUser(){
if (ISSET($_SESSION['email'])) {
$this->usrname = ($_SESSION['email']);
return $this->usrname;
}
return false;
}
function getLoggedInUserId($username = $this->usrname){
echo $username;
}
}
And calling the class file as
<?php
include "common.php"
$c = new Common;
$c->getLoggedInUserId();
Below is the error is shown for above call
Fatal error: Constant expression contains invalid operations
Please let me know how to pass function result as parameter for another function. Thanks