php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70756 Choice elements aren't working as expected
Submitted: 2015-10-21 09:02 UTC Modified: -
Votes:6
Avg. Score:4.5 ± 0.8
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:3 (50.0%)
From: php at xploseof dot com Assigned:
Status: Open Package: SOAP related
PHP Version: Irrelevant OS: CentOS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at xploseof dot com
New email:
PHP Version: OS:

 

 [2015-10-21 09:02 UTC] php at xploseof dot com
Description:
------------
We're using a classmap, together with protected properties for each property that might be in the requests/responses.

We're using the same classes for sending and receiving - an SDK as it were.

Our class has getters and setters - important to note here that the setters will throw an error if you try setting both, so it's a direct replication of what the XML allows, in programming form (as opposed to markup).

The issue comes about when there is a choice. There are two properties on the class, but the first of the XSD definition has no value (i.e. it is null).

It therefore ignores the second, and doesn't put in the first.

In these cases, I would expect it to work out "null" means it is not defined, and therefore look at the second option and so on.

Test script:
---------------
<xs:complexType name="Test">
	<xs:choice>
		<xs:element name="Item2" type="xs:string"/>
		<xs:element name="Item1" type="xs:string"/>
	</xs:choice>
</xs:complexType>

class Test
{
	protected $Item1;
	protected $Item2;
	
	public function get_item1()
	{
		return $this->Item1;
	}
	public function get_item2()
	{
		return $this->Item2;
	}
	public function set_item1($value)
	{
		if($this->Item2) {
			throw new \Exception('Can only define Item1 or Item2');
		}
	
		$this->Item1 = $value;
	}
	public function set_item2()
	{
		if($this->Item1) {
			throw new \Exception('Can only define Item1 or Item2');
		}
	
		$this->Item2 = $value;
	}
}


Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC