Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit 6cd3ad3

Browse files
committed
Merge pull request #306 from joomlatools/feature/247-php7
Ensure PHP7 compatibility
2 parents b7ed457 + 3df4ad6 commit 6cd3ad3

File tree

11 files changed

+144
-136
lines changed

11 files changed

+144
-136
lines changed

app/bootstrap.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
defined('_JEXEC') or die;
1111

12-
// Joomla system checks.
13-
@ini_set('magic_quotes_runtime', 0);
14-
1512
// Installation check, and check on removal of the install directory.
1613
if (!file_exists(JPATH_CONFIGURATION . '/configuration.php') || (filesize(JPATH_CONFIGURATION . '/configuration.php') < 10))
1714
{

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"ext-mbstring": "*",
2323
"joomla/application": "~1.2",
2424
"joomla/registry": "~1.2",
25-
"joomla/string": "~1.0",
26-
"joomla/uri": "~1.0",
25+
"joomla/string": "~1.3",
26+
"joomla/uri": "~1.1",
2727
"phpmailer/phpmailer": "5.2.9",
2828
"vlucas/phpdotenv": "^2.1.0",
2929
"joomlatools/console": "^1.4.0"

composer.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/libraries/cms/error/page.php

Lines changed: 75 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,73 +22,98 @@ class JErrorPage
2222
/**
2323
* Render the error page based on an exception.
2424
*
25-
* @param Exception $error The exception for which to render the error page.
25+
* @param object $error An Exception or Throwable (PHP 7+) object for which to render the error page.
2626
*
2727
* @return void
2828
*
2929
* @since 3.0
3030
*/
31-
public static function render(Exception $error)
31+
public static function render($error)
3232
{
33-
try
33+
$expectedClass = PHP_MAJOR_VERSION >= 7 ? 'Throwable' : 'Exception';
34+
$isException = $error instanceof $expectedClass;
35+
36+
// In PHP 5, the $error object should be an instance of Exception; PHP 7 should be a Throwable implementation
37+
if ($isException)
3438
{
35-
$app = JFactory::getApplication();
36-
$document = JDocument::getInstance('error');
37-
38-
$code = $error->getCode();
39-
if(!isset(JHttpResponse::$status_messages[$code])) {
40-
$code = '500';
41-
}
42-
43-
if(ini_get('display_errors')) {
44-
$message = $error->getMessage();
45-
} else {
46-
$message = JHttpResponse::$status_messages[$code];
47-
}
48-
49-
// Exit immediatly if we are in a CLI environment
50-
if (!$document || PHP_SAPI == 'cli')
39+
try
5140
{
52-
exit($message);
53-
$app->close(0);
54-
}
41+
$app = JFactory::getApplication();
42+
$document = JDocument::getInstance('error');
5543

56-
$config = JFactory::getConfig();
44+
$code = $error->getCode();
45+
if(!isset(JHttpResponse::$status_messages[$code])) {
46+
$code = '500';
47+
}
5748

58-
// Get the current template from the application
59-
$template = $app->getTemplate();
49+
if(ini_get('display_errors')) {
50+
$message = $error->getMessage();
51+
} else {
52+
$message = JHttpResponse::$status_messages[$code];
53+
}
6054

61-
$document->setError($error);
55+
if (!$document || PHP_SAPI == 'cli')
56+
{
57+
// We're probably in an CLI environment
58+
jexit($message);
59+
}
6260

63-
if (ob_get_contents()) {
64-
ob_end_clean();
65-
}
61+
// Get the current template from the application
62+
$template = $app->getTemplate();
6663

67-
$document->setTitle(JText::_('Error') . ': ' . $code);
68-
$data = $document->render(
69-
false,
70-
array('template' => $template,
71-
'directory' => JPATH_THEMES,
72-
'debug' => $config->get('debug'))
73-
);
64+
// Push the error object into the document
65+
$document->setError($error);
7466

75-
// Failsafe to get the error displayed.
76-
if (!empty($data))
77-
{
78-
// Do not allow cache
79-
$app->allowCache(false);
67+
if (ob_get_contents()) {
68+
ob_end_clean();
69+
}
70+
71+
$document->setTitle(JText::_('Error') . ': ' . $code);
72+
$data = $document->render(
73+
false,
74+
array(
75+
'template' => $template,
76+
'directory' => JPATH_THEMES,
77+
'debug' => JFactory::getConfig()->get('debug')
78+
)
79+
);
8080

81-
$app->setBody($data);
82-
echo $app->toString();
81+
// Do not allow cache
82+
$app->allowCache(false);
83+
84+
// If nothing was rendered, just use the message from the Exception
85+
if (empty($data))
86+
{
87+
$data = $message;
88+
}
89+
90+
$app->setBody($data);
91+
92+
echo $app->toString();
93+
94+
return;
95+
}
96+
catch (Exception $e)
97+
{
98+
// Pass the error down
8399
}
84-
else
85-
{
86-
exit($message);
87-
}
88100
}
89-
catch (Exception $e)
90-
{
91-
exit('Error displaying the error page: ' . $e->getMessage() . ': ' . $message);
101+
102+
// This isn't an Exception, we can't handle it.
103+
if (!headers_sent())
104+
{
105+
header('HTTP/1.1 500 Internal Server Error');
92106
}
107+
108+
$message = 'Error displaying the error page';
109+
110+
if ($isException)
111+
{
112+
$message .= ': ' . $e->getMessage() . ': ' . $message;
113+
}
114+
115+
echo $message;
116+
117+
jexit(1);
93118
}
94119
}

lib/libraries/cms/html/select.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ public static function option($value, $text = '', $optKey = 'value', $optText =
466466
}
467467

468468
$obj = new stdClass;
469-
$obj->$options['option.key'] = $value;
470-
$obj->$options['option.text'] = trim($text) ? $text : $value;
469+
$obj->{$options['option.key']} = $value;
470+
$obj->{$options['option.text']} = trim($text) ? $text : $value;
471471

472472
/*
473473
* If a label is provided, save it. If no label is provided and there is
@@ -478,23 +478,23 @@ public static function option($value, $text = '', $optKey = 'value', $optText =
478478
if (isset($options['label']))
479479
{
480480
$labelProperty = $hasProperty ? $options['option.label'] : 'label';
481-
$obj->$labelProperty = $options['label'];
481+
$obj->{$labelProperty} = $options['label'];
482482
}
483483
elseif ($hasProperty)
484484
{
485-
$obj->$options['option.label'] = '';
485+
$obj->{$options['option.label']} = '';
486486
}
487487

488488
// Set attributes only if there is a property and a value
489489
if ($options['attr'] !== null)
490490
{
491-
$obj->$options['option.attr'] = $options['attr'];
491+
$obj->{$options['option.attr']} = $options['attr'];
492492
}
493493

494494
// Set disable only if it has a property and a value
495495
if ($options['disable'] !== null)
496496
{
497-
$obj->$options['option.disable'] = $options['disable'];
497+
$obj->{$options['option.disable']} = $options['disable'];
498498
}
499499

500500
return $obj;
@@ -602,37 +602,37 @@ public static function options($arr, $optKey = 'value', $optText = 'text', $sele
602602
}
603603
elseif (is_object($element))
604604
{
605-
$key = $options['option.key'] === null ? $elementKey : $element->$options['option.key'];
606-
$text = $element->$options['option.text'];
605+
$key = $options['option.key'] === null ? $elementKey : $element->{$options['option.key']};
606+
$text = $element->{$options['option.text']};
607607

608-
if (isset($element->$options['option.attr']))
608+
if (isset($element->{$options['option.attr']}))
609609
{
610-
$attr = $element->$options['option.attr'];
610+
$attr = $element->{$options['option.attr']};
611611
}
612612

613-
if (isset($element->$options['option.id']))
613+
if (isset($element->{$options['option.id']}))
614614
{
615-
$id = $element->$options['option.id'];
615+
$id = $element->{$options['option.id']};
616616
}
617617

618-
if (isset($element->$options['option.label']))
618+
if (isset($element->{$options['option.label']}))
619619
{
620-
$label = $element->$options['option.label'];
620+
$label = $element->{$options['option.label']};
621621
}
622622

623-
if (isset($element->$options['option.disable']) && $element->$options['option.disable'])
623+
if (isset($element->{$options['option.disable']}) && $element->{$options['option.disable']})
624624
{
625625
$extra .= ' disabled="disabled"';
626626
}
627627

628-
if (isset($element->$options['option.class']) && $element->$options['option.class'])
628+
if (isset($element->{$options['option.class']}) && $element->{$options['option.class']})
629629
{
630-
$extra .= ' class="' . $element->$options['option.class'] . '"';
630+
$extra .= ' class="' . $element->{$options['option.class']} . '"';
631631
}
632632

633-
if (isset($element->$options['option.onclick']) && $element->$options['option.onclick'])
633+
if (isset($element->{$options['option.onclick']}) && $element->{$options['option.onclick']})
634634
{
635-
$extra .= ' onclick="' . $element->$options['option.onclick'] . '"';
635+
$extra .= ' onclick="' . $element->{$options['option.onclick']} . '"';
636636
}
637637
}
638638
else

lib/libraries/cms/menu/menu.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ public function getItems($attributes, $values, $firstonly = false)
266266
{
267267
if (is_array($values[$i]))
268268
{
269-
if (!in_array($item->$attributes[$i], $values[$i]))
269+
if (!in_array($item->{$attributes[$i]}, $values[$i]))
270270
{
271271
$test = false;
272272
break;
273273
}
274274
}
275275
else
276276
{
277-
if ($item->$attributes[$i] != $values[$i])
277+
if ($item->{$attributes[$i]} != $values[$i])
278278
{
279279
$test = false;
280280
break;

lib/libraries/joomla/database/driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ abstract public function getAffectedRows();
584584
*
585585
* @since 12.2
586586
*/
587-
protected function getAlterDbCharacterSet($dbName)
587+
public function getAlterDbCharacterSet($dbName)
588588
{
589589
return 'ALTER DATABASE ' . $this->quoteName($dbName) . ' CHARACTER SET `utf8`';
590590
}

lib/libraries/joomla/document/error/error.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public function __construct($options = array())
5656
*/
5757
public function setError($error)
5858
{
59-
if ($error instanceof Exception)
59+
$expectedClass = PHP_MAJOR_VERSION >= 7 ? 'Throwable' : 'Exception';
60+
61+
if ($error instanceof $expectedClass)
6062
{
6163
$this->_error = & $error;
6264
return true;
6365
}
64-
else
65-
{
66-
return false;
67-
}
66+
67+
return false;
6868
}
6969

7070
/**

lib/libraries/joomla/string/string.php

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,24 @@
1919
* @package Joomla.Platform
2020
* @subpackage String
2121
* @since 11.1
22+
* @deprecated 4.0 Use {@link \Joomla\String\StringHelper} instead unless otherwise noted.
2223
*/
2324
abstract class JString extends StringHelper
2425
{
25-
/**
26-
* Does a UTF-8 safe version of PHP parse_url function
27-
*
28-
* @param string $url URL to parse
29-
*
30-
* @return mixed Associative array or false if badly formed URL.
31-
*
32-
* @see http://us3.php.net/manual/en/function.parse-url.php
33-
* @since 11.1
34-
*/
35-
public static function parse_url($url)
36-
{
37-
$result = false;
38-
39-
// Build arrays of values we need to decode before parsing
40-
$entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%24', '%2C', '%2F', '%3F', '%23', '%5B', '%5D');
41-
$replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "$", ",", "/", "?", "#", "[", "]");
42-
43-
// Create encoded URL with special URL characters decoded so it can be parsed
44-
// All other characters will be encoded
45-
$encodedURL = str_replace($entities, $replacements, urlencode($url));
46-
47-
// Parse the encoded URL
48-
$encodedParts = parse_url($encodedURL);
49-
50-
// Now, decode each value of the resulting array
51-
if ($encodedParts)
52-
{
53-
foreach ($encodedParts as $key => $value)
54-
{
55-
$result[$key] = urldecode(str_replace($replacements, $entities, $value));
56-
}
57-
}
58-
59-
return $result;
60-
}
26+
/**
27+
* Does a UTF-8 safe version of PHP parse_url function
28+
*
29+
* @param string $url URL to parse
30+
*
31+
* @return mixed Associative array or false if badly formed URL.
32+
*
33+
* @see http://us3.php.net/manual/en/function.parse-url.php
34+
* @since 11.1
35+
* @deprecated 4.0 (CMS) - Use {@link \Joomla\Uri\UriHelper::parse_url()} instead.
36+
*/
37+
public static function parse_url($url)
38+
{
39+
JLog::add('JString::parse_url has been deprecated. Use \\Joomla\\Uri\\UriHelper::parse_url.', JLog::WARNING, 'deprecated');
40+
return \Joomla\Uri\UriHelper::parse_url($url);
41+
}
6142
}

lib/libraries/joomla/utilities/arrayhelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@ protected static function _sortObjects(&$a, &$b)
551551
$locale = self::$sortLocale[$i];
552552
}
553553

554-
$va = $a->$key[$i];
555-
$vb = $b->$key[$i];
554+
$va = $a->{$key[$i]};
555+
$vb = $b->{$key[$i]};
556556

557557
if ((is_bool($va) || is_numeric($va)) && (is_bool($vb) || is_numeric($vb)))
558558
{

0 commit comments

Comments
 (0)