|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31785 Add Mulitple Type hinting
Submitted: 2005-01-31 23:18 UTC Modified: 2005-01-31 23:55 UTC
From: CaptainN at adcstudio dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
 [2005-01-31 23:18 UTC] CaptainN at adcstudio dot com
Since php is a dynamicly typed language, it would be great if we could supply multiple type hints for a function or method.

This would kind of be like function argument type overloading, where the overload is handled within the same function.

It could look something like the example below. In this example, both Class1 and Class2 could have __toString methods defined, so that it doesn't matter what the rest of the class looks like, since this function is just going to convert them to strings, then output that value anyway:

Reproduce code:
function testFunction(ClassName1|ClassName2 $Obj) {
	echo 'Class Info: ' . $Obj;

Another example (combined with support for built in types in type hinting):

function SetupDatabase(DatabaseConfig|boolean $config=false) {
	if ($config) {
		$this->config = $config;

Expected result:
If this is not the proper place to post these kinds of requests/feature explorations, please let me know.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-31 23:55 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

1) Use interfaces
2) We will never add support for base types
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Oct 15 21:03:43 2021 UTC