Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 8dbf37e

Browse files
committed
Merge pull request zendframework/zendframework#2210 from weierophinney/hotfix/remove-suppression-operator
Get rid of error suppression

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

src/Collection/DefaultIterator.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Zend\Ldap;
1414
use Zend\Ldap\Exception;
15+
use Zend\Stdlib\ErrorHandler;
1516

1617
/**
1718
* Zend\Ldap\Collection\DefaultIterator is the default collection iterator implementation
@@ -73,7 +74,10 @@ public function __construct(Ldap\Ldap $ldap, $resultId)
7374
{
7475
$this->ldap = $ldap;
7576
$this->resultId = $resultId;
76-
$this->itemCount = @ldap_count_entries($ldap->getResource(), $resultId);
77+
78+
ErrorHandler::start();
79+
$this->itemCount = ldap_count_entries($ldap->getResource(), $resultId);
80+
ErrorHandler::stop();
7781
if ($this->itemCount === false) {
7882
throw new Exception\LdapException($this->ldap, 'counting entries');
7983
}
@@ -93,7 +97,10 @@ public function close()
9397
{
9498
$isClosed = false;
9599
if (is_resource($this->resultId)) {
96-
$isClosed = @ldap_free_result($this->resultId);
100+
ErrorHandler::start();
101+
$isClosed = ldap_free_result($this->resultId);
102+
ErrorHandler::stop();
103+
97104
$this->resultId = null;
98105
$this->current = null;
99106
}
@@ -191,13 +198,26 @@ public function current()
191198

192199
$entry = array('dn' => $this->key());
193200
$ber_identifier = null;
194-
$name = @ldap_first_attribute(
201+
202+
ErrorHandler::start();
203+
$name = ldap_first_attribute(
195204
$this->ldap->getResource(), $this->current,
196205
$ber_identifier
197206
);
207+
ErrorHandler::stop();
208+
198209
while ($name) {
199-
$data = @ldap_get_values_len($this->ldap->getResource(), $this->current, $name);
200-
unset($data['count']);
210+
ErrorHandler::start();
211+
$data = ldap_get_values_len($this->ldap->getResource(), $this->current, $name);
212+
ErrorHandler::stop();
213+
214+
if (!$data) {
215+
$data = array();
216+
}
217+
218+
if (isset($data['count'])) {
219+
unset($data['count']);
220+
}
201221

202222
switch ($this->attributeNameTreatment) {
203223
case self::ATTRIBUTE_TO_LOWER:
@@ -214,10 +234,13 @@ public function current()
214234
break;
215235
}
216236
$entry[$attrName] = $data;
217-
$name = @ldap_next_attribute(
237+
238+
ErrorHandler::start();
239+
$name = ldap_next_attribute(
218240
$this->ldap->getResource(), $this->current,
219241
$ber_identifier
220242
);
243+
ErrorHandler::stop();
221244
}
222245
ksort($entry, SORT_LOCALE_STRING);
223246
return $entry;
@@ -236,7 +259,10 @@ public function key()
236259
$this->rewind();
237260
}
238261
if (is_resource($this->current)) {
239-
$currentDn = @ldap_get_dn($this->ldap->getResource(), $this->current);
262+
ErrorHandler::start();
263+
$currentDn = ldap_get_dn($this->ldap->getResource(), $this->current);
264+
ErrorHandler::stop();
265+
240266
if ($currentDn === false) {
241267
throw new Exception\LdapException($this->ldap, 'getting dn');
242268
}
@@ -259,7 +285,9 @@ public function next()
259285
$code = 0;
260286

261287
if (is_resource($this->current) && $this->itemCount > 0) {
262-
$this->current = @ldap_next_entry($this->ldap->getResource(), $this->current);
288+
ErrorHandler::start();
289+
$this->current = ldap_next_entry($this->ldap->getResource(), $this->current);
290+
ErrorHandler::stop();
263291
if ($this->current === false) {
264292
$msg = $this->ldap->getLastError($code);
265293
if ($code === Exception\LdapException::LDAP_SIZELIMIT_EXCEEDED) {
@@ -284,7 +312,9 @@ public function next()
284312
public function rewind()
285313
{
286314
if (is_resource($this->resultId)) {
287-
$this->current = @ldap_first_entry($this->ldap->getResource(), $this->resultId);
315+
ErrorHandler::start();
316+
$this->current = ldap_first_entry($this->ldap->getResource(), $this->resultId);
317+
ErrorHandler::stop();
288318
if ($this->current === false
289319
&& $this->ldap->getLastErrorCode() > Exception\LdapException::LDAP_SUCCESS
290320
) {

src/Converter/Converter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use DateTime;
1414
use DateTimeZone;
15+
use Zend\Stdlib\ErrorHandler;
1516

1617
/**
1718
* Zend\Ldap\Converter is a collection of useful LDAP related conversion functions.
@@ -382,7 +383,10 @@ public static function fromLdapBoolean($value)
382383
*/
383384
public static function fromLdapUnserialize($value)
384385
{
385-
$v = @unserialize($value);
386+
ErrorHandler::start(E_NOTICE);
387+
$v = unserialize($value);
388+
ErrorHandler::stop();
389+
386390
if (false === $v && $value != 'b:0;') {
387391
throw new Exception\UnexpectedValueException('The given value could not be unserialized');
388392
}

src/Ldap.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,9 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
722722
/* Only OpenLDAP 2.2 + supports URLs so if SSL is not requested, just
723723
* use the old form.
724724
*/
725-
$resource = ($useUri) ? @ldap_connect($this->connectString) : @ldap_connect($host, $port);
725+
ErrorHandler::start();
726+
$resource = ($useUri) ? ldap_connect($this->connectString) : ldap_connect($host, $port);
727+
ErrorHandler::stop();
726728

727729
if (is_resource($resource) === true) {
728730
$this->resource = $resource;
@@ -736,7 +738,7 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
736738
if ($networkTimeout) {
737739
ldap_set_option($resource, LDAP_OPT_NETWORK_TIMEOUT, $networkTimeout);
738740
}
739-
if ($useSsl || !$useStartTls || @ldap_start_tls($resource)) {
741+
if ($useSsl || !$useStartTls || ldap_start_tls($resource)) {
740742
ErrorHandler::stop();
741743
return $this;
742744
}

0 commit comments

Comments
 (0)