Do not use function is_resource().

PHP 8.1 replaces some kind of resources by built-in class instances.
As is_resource() is always used to test for failures, replace calls by
simple Boolean checks.
This commit is contained in:
Patrick Monnerat 2022-05-30 20:13:04 +02:00 committed by Deon George
parent f129579f45
commit b035e8a0f4
2 changed files with 19 additions and 17 deletions

View File

@ -40,7 +40,7 @@ switch ($request['location']) {
if (! isset($jpeg_data[$request['attr']][$request['index']])) { if (! isset($jpeg_data[$request['attr']][$request['index']])) {
if (function_exists('imagecreate')) { if (function_exists('imagecreate')) {
$im = imagecreate(160,30); $im = imagecreate(160,30);
if (is_resource($im)) { if ($im) {
header('Content-type: image/png'); header('Content-type: image/png');
# Set the background # Set the background

View File

@ -216,7 +216,7 @@ class ldap extends DS {
debug_log('LDAP Resource [%s], Host [%s], Port [%s]',16,0,__FILE__,__LINE__,__METHOD__, debug_log('LDAP Resource [%s], Host [%s], Port [%s]',16,0,__FILE__,__LINE__,__METHOD__,
$resource,$this->getValue('server','host'),$this->getValue('server','port')); $resource,$this->getValue('server','host'),$this->getValue('server','port'));
if (! is_resource($resource)) if (!$resource)
debug_dump_backtrace('UNHANDLED, $resource is not a resource',1); debug_dump_backtrace('UNHANDLED, $resource is not a resource',1);
# Go with LDAP version 3 if possible (needed for renaming and Novell schema fetching) # Go with LDAP version 3 if possible (needed for renaming and Novell schema fetching)
@ -337,7 +337,7 @@ class ldap extends DS {
$connect = $this->connect($method,false,$new); $connect = $this->connect($method,false,$new);
# If we didnt log in... # If we didnt log in...
if (! is_resource($connect) || $this->noconnect || ! $this->userIsAllowedLogin($userDN)) { if (!$connect || $this->noconnect || ! $this->userIsAllowedLogin($userDN)) {
$this->logout($method); $this->logout($method);
return false; return false;
@ -410,22 +410,24 @@ class ldap extends DS {
if ($debug) if ($debug)
debug_dump(array('query'=>$query,'server'=>$this->getIndex(),'con'=>$this->connect($method))); debug_dump(array('query'=>$query,'server'=>$this->getIndex(),'con'=>$this->connect($method)));
$search = null;
$resource = $this->connect($method,$debug); $resource = $this->connect($method,$debug);
switch ($query['scope']) { if ($resource)
case 'base': switch ($query['scope']) {
$search = @ldap_read($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']); case 'base':
break; $search = @ldap_read($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']);
break;
case 'one': case 'one':
$search = @ldap_list($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']); $search = @ldap_list($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']);
break; break;
case 'sub': case 'sub':
default: default:
$search = @ldap_search($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']); $search = @ldap_search($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$query['time_limit'],$query['deref']);
break; break;
} }
if ($debug) if ($debug)
debug_dump(array('method'=>$method,'search'=>$search,'error'=>$this->getErrorMessage())); debug_dump(array('method'=>$method,'search'=>$search,'error'=>$this->getErrorMessage()));
@ -1288,7 +1290,7 @@ class ldap extends DS {
$search = @ldap_read($this->connect($method),$dn,'objectclass=*',array('subschemaSubentry'),false,0,10,LDAP_DEREF_NEVER); $search = @ldap_read($this->connect($method),$dn,'objectclass=*',array('subschemaSubentry'),false,0,10,LDAP_DEREF_NEVER);
if (DEBUG_ENABLED) if (DEBUG_ENABLED)
debug_log('Search returned (%s)',24,0,__FILE__,__LINE__,__METHOD__,is_resource($search)); debug_log('Search returned (%s)',24,0,__FILE__,__LINE__,__METHOD__,!!$search);
# Fix for broken ldap.conf configuration. # Fix for broken ldap.conf configuration.
if (! $search && ! $dn) { if (! $search && ! $dn) {
@ -1301,7 +1303,7 @@ class ldap extends DS {
if (DEBUG_ENABLED) if (DEBUG_ENABLED)
debug_log('Search returned (%s) for base (%s)',24,0,__FILE__,__LINE__,__METHOD__, debug_log('Search returned (%s) for base (%s)',24,0,__FILE__,__LINE__,__METHOD__,
is_resource($search),$base); !!$search,$base);
if ($search) if ($search)
break; break;