#46560 [NEW]: Addition of magic method "__valueOf" allowing object conversion to number

2008-11-12 Thread jonasraoni at gmail dot com
From: jonasraoni at gmail dot com
Operating system: 
PHP version:  5.3.0alpha2
PHP Bug Type: Feature/Change Request
Bug description:  Addition of magic method "__valueOf" allowing object 
conversion to number

Description:

In the current implementation it's impossible to convert an object to a
number.

I should exist a magic method called "__valueOf" which must return a
float/int. In the case this magic method isn't declared , it should be
returned a not zero value when converting to number (it happens, but
generates the E_NOTICE anyway).

Reproduce code:
---
class Number{
private $value;
public function __construct($n){
$this->value = +$n;
}
public function __toString(){
return (string)$this->value;
}
public function __valueOf(){
return $this->value;
}
}

$n = new Number(2);
echo $n . ':' . +$n;

Expected result:

2:2

Actual result:
--
Notice: Object of class Number could not be converted to int in
C:\test.php on line 16
2:1

-- 
Edit bug report at http://bugs.php.net/?id=46560&edit=1
-- 
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46560&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46560&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46560&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=46560&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=46560&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=46560&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=46560&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=46560&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=46560&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=46560&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=46560&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=46560&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=46560&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=46560&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=46560&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=46560&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=46560&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=46560&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=46560&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=46560&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=46560&r=mysqlcfg



Bug #33366 [Com]: __soapCall Produces Incorrect Request

2011-07-15 Thread jonasraoni at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=33366&edit=1

 ID: 33366
 Comment by: jonasraoni at gmail dot com
 Reported by:cmantunes at gmail dot com
 Summary:__soapCall Produces Incorrect Request
 Status: Bogus
 Type:   Bug
 Package:SOAP related
 Operating System:   Debian
 PHP Version:5.1.0
 Assigned To:dmitry
 Block user comment: N
 Private report: N

 New Comment:

I have the same problem as "cmantunes" (I'm using an WSDL too), and many more 
at the same request.

#1. First argument being ripped off from the XML when calling directly 
($client->method(args))

#2. After adding a bogus first parameter, the request got the method name 
closed and, the param was placed after it, just like the guy mentioned. And, 
also with the wrong name, the param should be "arg0" and it was displayed as 
"param1".

#3. Even after fixing the request, the response is also misunderstood by the 
extension! I had to make more workarounds to remove the trailing data (which 
seems to be part of a standard, the request works fine when I tested with the 
soapUI client):

--uuid:6365a322-9529-4cf5-b3bb-4ed69bd78b38
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: 

http://schemas.xmlsoap.org/soap/envelope/";>
[...]
--uuid:6365a322-9529-4cf5-b3bb-4ed69bd78b38--


#4. When using Apache 2.2.X on Windows and requesting a WSDL through HTTPS "new 
SoapClient" crashes Apache. It works fine just on IIS, I tested with several 
PHP versions and, also the latest (currently 5.3.6).

I had tried the suggested code by Dmitry before and it didn't work out.

Unhappily I made workarounds at the __doRequest to solve my immediate problems.


Previous Comments:

[2005-06-17 10:03:33] dmi...@php.net

Hi,

The ext/soap is match easy in usage then you expected.
You should use the following code:

$isc->getOperationCount(array(
'startDate' => '2005-04-01',
'endDate'   => '2005-04-01'
  ));

or 

$isc->__soapCall('getOperationCount', array(
array('getOperationCount' => array(
  'startDate' => '2005-04-01',
  'endDate'   => '2005-04-01'
  )));

You don't need to use SoapParam if you use WSDL.


[2005-06-16 20:33:24] cmantunes at gmail dot com

As requested, I attempted the same code with the latest snapshot 
(php5-200506161630) but __soapCall continues to exhibit the same buggy behavior 
as before. As such, the problem doesn't appear to have been corrected yet. 
Thank you!


[2005-06-16 18:56:00] sni...@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip




[2005-06-16 18:44:22] cmantunes at gmail dot com

Description:

When using SoapClient->__soapCall with parameters, the request  is incorrectly 
encoded regarding the method parameters. The first SoapParam is also ignored.

Reproduce code:
---
#!/usr/bin/php

https://adwords.google.com/api/adwords/v2";;

  // InfoService client
  $isc=new SoapClient($ns . '/InfoService?wsdl',
  array('trace'=>1, 'exceptions'=>1)
 );
  try
  {
//
// BUG: __soapCall *IGNORES* the first parameter!
// That's why 'null' is being used
//
$params=array(null,
new SoapParam('2005-04-01', 'startDate'),
new SoapParam('2005-04-30', 'endDate'));

//
// BUG: This Call produces:
//  ->CLOSED ALREADY!
//   2005-04-01
//   2005-04-30
//
$isc->__soapCall('getOperationCount', $params);
  }
  catch (Exception $e)
  {
print_r($e);
  }

  print "Request:\n\n" .
$isc->__getLastRequest() . "\n\n\n";
  print "Response:\n\n" .
$isc->__getLastResponse() . "\n\n\n";

?>

Expected result:


2005-04-01
2005-04-30



Actual result:
--

2005-04-01
2005-04-30







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


Bug #33366 [Com]: __soapCall Produces Incorrect Request

2011-07-30 Thread jonasraoni at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=33366&edit=1

 ID: 33366
 Comment by: jonasraoni at gmail dot com
 Reported by:cmantunes at gmail dot com
 Summary:__soapCall Produces Incorrect Request
 Status: Bogus
 Type:   Bug
 Package:SOAP related
 Operating System:   Debian
 PHP Version:5.1.0
 Assigned To:dmitry
 Block user comment: N
 Private report: N

 New Comment:

Here are the fixes I had to make in order to get it working for *my* needs. I 
believe it will help the other users that had this problem (I found many cases 
on internet, but no fixes).

class FixedSOAPClient extends SoapClient{
private $method;
private $argumentCount;
/*
Loading the WSDL through PHP instead of letting the SoapClient do this 
job, avoids breaking Apache. I noticed it breaks just here, while loading the 
wsdl through *HTTPS*.
Note: I believe that the __doRequest method should also be called when 
loading the .wsdl
*/
public function __construct($url){
$s = file_get_contents($url);
file_put_contents($url = md5($url) . '.wsdl', $s);
parent::__construct($url, array(
'compression' => SOAP_COMPRESSION_ACCEPT | 
SOAP_COMPRESSION_GZIP
));
}
public function __call($function, $arguments){
$this->argumentCount = count($arguments);
/*
Adding a bogus parameter to the beginning, since the SoapClient 
is "eating" the first argument.
*/
array_unshift($arguments, 0);
return parent::__call($this->method = $function, $arguments);
}
public function __doRequest($request, $location, $action, $version, 
$oneWay = 0){
$xml = new DOMDocument('1.0', 'utf-8');
$xml->loadXML($request);
$d = $xml->documentElement;
/*
Placing the "lost" arguments inside the function node, their 
right place.
*/
for($o = $d->getElementsByTagName($this->method)->item(0); 
$o->nextSibling; $o->appendChild($o->nextSibling));

$xml = $xml->saveXML();
/*
The operation expected parameters to be named as arg1, arg2, 
insted of what PHP built, which was param1, param2...
*/
if($this->argumentCount)
foreach(range($this->argumentCount, 0) as $i)
$xml = str_replace('param' . ($i + 1), 'arg' . 
$i, $xml);
/*
Removing boundary from the XML result, this must be part of a 
standard as the calls works fine on other tools, the SoapClient should be able 
to handle it.
*/
$s = preg_replace('/--.*?--$/', '', 
preg_replace('/^(?:.|\n|\r)*?method(args))

#2. After adding a bogus first parameter, the request got the method name 
closed and, the param was placed after it, just like the guy mentioned. And, 
also with the wrong name, the param should be "arg0" and it was displayed as 
"param1".

#3. Even after fixing the request, the response is also misunderstood by the 
extension! I had to make more workarounds to remove the trailing data (which 
seems to be part of a standard, the request works fine when I tested with the 
soapUI client):

--uuid:6365a322-9529-4cf5-b3bb-4ed69bd78b38
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: 

http://schemas.xmlsoap.org/soap/envelope/";>
[...]
--uuid:6365a322-9529-4cf5-b3bb-4ed69bd78b38--


#4. When using Apache 2.2.X on Windows and requesting a WSDL through HTTPS "new 
SoapClient" crashes Apache. It works fine just on IIS, I tested with several 
PHP versions and, also the latest (currently 5.3.6).

I had tried the suggested code by Dmitry before and it didn't work out.

Unhappily I made workarounds at the __doRequest to solve my immediate problems.


[2005-06-17 10:03:33] dmi...@php.net

Hi,

The ext/soap is match easy in usage then you expected.
You should use the following code:

$isc->getOperationCount(array(
'startDate' => '2005-04-01',
'endDate'   => '2005-04-01'
  ));

or 

$isc->__soapCall('getOperationCount', array(
array('getOperationCount' => array(
  'startDate' => '2005-04-01',
  'endDate'   => '2005-04-01'
  )));

You don't need to use SoapParam if you use WSDL.

-