Jump to content

Recommended Posts

Posted

I have the following class:

SGNBEResponseCode class:

<?php
namespace SGNBackend\SGNBEResponseCodes;

class SGNBEResponseCode {
	public function __construct(){
		print_r(__CLASS__);
		return __CLASS__;
	}
}
?>
<?php
namespace SGNBackend\SGNBEResponseCodes;

class Common extends SGNBEResponseCode {
	public const UNKNOWN_ERROR = -1;
	public const INVALID_REQUEST = 0;
	public const REQ_FAILED = 100;
	public const DB_QUERY_ERROR = 101;
	public const DB_COUNT_ERROR = 102;
	public const DB_FETCH_ERROR = 103;
	public const EMPTY_PARAM_VALUE = 104;
	public const INVALID_PARAM_VALUE = 105;
	public const REQ_DONE = 106;

	public function __construct(){
		print_r(__CLASS__);
		return __CLASS__;
	}
}
?>
Here SGNBEResponse class:

<?php
namespace SGNBackend;

class SGNBEResponse{
	const response = array("error"=>true, "code"=>-1, "name"=>"UNKNOWN_ERROR", "message"=>"An unknown error has occurred");

	public static function generateErrorFromCode(SGNBEResponseCode $code, string $args = null){
		$c = debug_backtrace();
		print_r($c);
		//return "test";
	}
}
?>
And I'm trying to access the constants like this:

<?php
$sgnbe = new \SGNBackend\SGNBEResponse();
print_r(\SGNBackend\SGNBEResponse::generateErrorFromCode(\SGNBackend\SGNBEResponseCodes\Common::INVALID_REQUEST));
?>
And when I access the constants an instance of the class along with the name of the constant and value should be returned instead of the value of the constants. Can I do it? If yes then how?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...