CreationAgent Posted September 2, 2020 Share Posted September 2, 2020 We have a client with an older site that we haven't touched in a few years. The hosting provider is updating to PHP 7.3 mid september. From our test site there appears to be only one piece of code that needs to be updated for PHP 7.3. It's below and used to detect the initial path of the page the visitor is viewing, e.g. /educators/ or /parents/ etc. in order to display some special links in the navigation server side include. http://domainname.com/educators/ http://domainname.com/educators/other-url-here/ http://domainname.com/parents/other-url-parts-here/ <?php //GLOBAL PHP VARIABLES //get current directory site path and change code links based off of that. class dir { function dir() { $location = $_SERVER["SCRIPT_NAME"]; list($this->dir) = split("[a-zA-Z0-9_\-]*.php$", $location, 2); } } $directory = new dir(); $sitepath = $directory->dir; ?> The server error that comes back is this....Fatal error: Uncaught Error: Call to undefined function split() in /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/includes/topnav_parents.php:9 Stack trace: #0 /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/includes/topnav_parents.php(12): dir->dir() #1 /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/parents/index.php(108): include('/nfs/c03/h03/mn...') #2 {main} thrown in /nfs/c03/h03/mnt/46929/domains/domain-name-removed/html/includes/topnav_parents.php on line 9(I changed the site's domain name in the error message above domain-named-removed for client privacy) We were using the $sitepath variable for some logic to display specific banner set blocks of content lower down in the footer section based on if ($sitepath == "/parents/") we show one set or if the $sitepath == "/educators/" we display a different set. If any of you PHP 7 guys know what the issue is, please advise. I would be most grateful. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/311422-php-53-7-code-fix-help/ Share on other sites More sharing options...
dodgeitorelse3 Posted September 2, 2020 Share Posted September 2, 2020 This tip is taken from https://www.php.net/manual/en/function.split.php Tip split() is deprecated as of PHP 5.3.0. preg_split() is the suggested alternative to this function. If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine. Quote Link to comment https://forums.phpfreaks.com/topic/311422-php-53-7-code-fix-help/#findComment-1581096 Share on other sites More sharing options...
CreationAgent Posted September 3, 2020 Author Share Posted September 3, 2020 @dodgeitorelse3 Thank you for the split(); deprecation note AND the tip to use the explode(); function instead. VERY MUCH APPRECIATED! Quote Link to comment https://forums.phpfreaks.com/topic/311422-php-53-7-code-fix-help/#findComment-1581110 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.