php.net |  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
Description:
------------
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;
	}
	$this->Connect();
}

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

Thanks.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

1) Use interfaces
2) We will never add support for base types
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC