使用未定义的常量PHP 7.2

时间:2019-11-21 00:16:08

标签: php undefined

自更新以来,我偶尔会看到此警告

  

警告:使用未定义的常量SSL_CURRENT-假定为“ SSL_CURRENT”   (这会在将来的PHP版本中引发错误)   /usr/www/domain/phpmyd/listing.php,第151行

这是一行:

$pdf->Image($PMDR->get($PMDR->getConfig('map_type').'_Map')->getMapImageByCoords($listing['latitude'],$listing['longitude']),$pdf->GetX(),$pdf->GetY(),$pdf->pixelsToUnits(512),$pdf->pixelsToUnits(512),'','http'.(SSL_CURRENT ? 's' : '').'://maps.google.com/maps?q='.$listing['latitude'].','.$listing['longitude'],'N', false, 300);

只看它,应该像

$pdf->pixelsToUnits(512),'','http'.('SSL_CURRENT' ? 's' : '')

因此,只需在SSL_current周围添加方括号?总是这样吗,因为我以前从未见过错误。

1 个答案:

答案 0 :(得分:1)

我看过PHP的来源,并且常量SSL_CURRENT从未在从版本4开始的任何PHP版本中定义。

因此,此问题与PHP版本的更改无关。

无论出于何种原因,您之前都看不到有关该常量的警告,但是可以肯定的是,没有PHP版本更新使该常量未定义。

由于此字符串:

'SSL_CURRENT'

将始终取值为true,然后此条件表达式:

'SSL_CURRENT' ? 's' : '';

完全没有条件,因为它将始终返回“ s”:

echo 'SSL_CURRENT' ? 's' : '';

所以也可以这样写

echo 's';

因此等同于以这种方式在您的代码中使用它:

$pdf->pixelsToUnits(512),'','https'