Req #60432 [Com]: Improving typehinting in function args

2012-03-05 Thread daanleduc at hotmail dot com
Edit report at https://bugs.php.net/bug.php?id=60432&edit=1

 ID: 60432
 Comment by: daanleduc at hotmail dot com
 Reported by:duke at ejoom dot com
 Summary:Improving typehinting in function args
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:5.4.0RC2
 Block user comment: N
 Private report: N

 New Comment:

Would be also nice if its possible to add an more strict mode for functions.
For example ->

function test(int $int, string $string, float $float) {}

behavior -> 

function('test', 12, "blaat") {} <-- shouldn't throw

ini_set('function_strict', true);
function('test', 12, "blaat") {} <-- should throw

It should be really strict so if its not an int it is not valid (triple === 
check). Even if its an int string ("1").

What duke suggest is nice but still breaks if you do an bool (true) in an int, 
its casts safely to int 1. Should just throw if you put the strict mode on or 
maybe build some levels of strict mode.

It would save me and a lot of other developers all the sanity checks.


Previous Comments:

[2011-12-02 21:26:12] duke at ejoom dot com

It can be possible to use the function to delete rows in DB:
function delete( array $ids ) { //some code}

delete(3); //will work correct as expected.
// Or
delete(array(3,6));// will work.


Or we would be able to use that behaviour: 
$object->property1 = 1;
$object->property2 = 'value';
tipehind($object);
//where $object converting into array.


[2011-12-02 21:12:43] duke at ejoom dot com

Description:

I want to discuss an improving typehint.

I propose to do typehint behaviour as following:
On the Object instance it will behave as current (emit an error).
At the array int and float it must do equivalence:

function typehint( array $array, string $string, int $int, float $float )
{}
   will be equivalent to
function typehint( $array, $string, $int, $float )
{
if (is_array($array) === false) $array = (array) $array;
$string = (string) $string;
$int = (int) $int;
$float = (float) $float;
}

It will do code more readable and compact. For Zend Framework DB it will do 
easier typing query where escaping is based on type of var,

Isn't logical emit error on mismatching of type on int and string at PHP caused 
by easing change type against C or C++. So we must use it feature of PHP and do 
life easier ;).







-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60432&edit=1


Req #32177 [Com]: ReflectionException

2012-03-05 Thread daanleduc at hotmail dot com
Edit report at https://bugs.php.net/bug.php?id=32177&edit=1

 ID: 32177
 Comment by: daanleduc at hotmail dot com
 Reported by:pawel dot kozlowski at gmail dot com
 Summary:ReflectionException
 Status: Assigned
 Type:   Feature/Change Request
 Package:Reflection related
 Operating System:   Any
 PHP Version:5.0.3
 Assigned To:johannes
 Block user comment: N
 Private report: N

 New Comment:

Had the same problem fixed it like this ->

http://stackoverflow.com/questions/4513867/php-reflection-get-method-parameter-
type-as-string/9500359#9500359

Would be better if there is an getClassName on reflection parameter.


Previous Comments:

[2005-03-03 16:29:24] pawel dot kozlowski at gmail dot com

Description:

I’m trying to use Reflection API. I works great, but I’ve some remarks 
regarding ReflectionException. Calling ReflectionParameter::getClass() will 
raise an exception when class definition isn’t already included. That’s fine, 
it’s an expected behavior. The problem is that I have no way to get the missing 
class name. Ok, I could parse message string, but this way it becomes 
(unintentionally) part of  the public API. What do You think about having sth 
like

Class ReflectionExceptionClassNotDefined extends ReflectionException
{
public string getClassName();

}


Reproduce code:
---
class A
{
public function __construct(B $b)
{
   $this->b = $b;
}
}

$rc = new ReflectionClass('A');
$rconstr = $rc->getConstructor();
$rparams = $rconstr->getParameters();

try
{
   $paramclass = $rparams[0]->getClass();
}
catch (ReflectionException $e)
{
   //no way to get 'B' name here, without parsing msg string
}







-- 
Edit this bug report at https://bugs.php.net/bug.php?id=32177&edit=1