PHP: constant as variable in function

Posted by m4recek on Stack Overflow See other posts from Stack Overflow or by m4recek
Published on 2012-06-17T21:09:39Z Indexed on 2012/06/17 21:16 UTC
Read the original article Hit count: 137

Filed under:
|
|

I'm trying to use constant as a function paramter, is it possible to check type of this constant.

Example of what I want:

class ApiError {
  const INVALID_REQUEST = 200;
}

class Response {
  public function status(ApiError $status) {
    //function code here
  }
}

USE:

$response = new Response();
$response->status(ApiError::INVALID_REQUEST);

This shoud check that given $status is constant of class ApiError. Is something like this possible?

© Stack Overflow or respective owner

Related posts about php

Related posts about constants