← Back to Custom Fields CMS Support
Hi I just installed the plugin to add a textfield to a CMS page. When saving the page with content in the newly created field I get: "Trying to access array offset on value of type null" on line 85 of /mnt/web006/c1/10/56956010/htdocs/morff.nl/waakvlam/plugins/shohabbos/customfields/Plugin.php
Mayby this has to do with php7.4
Hi, to those who may want to try fixing the error themselves, as the plugin does not seem to be maintained anymore the last edits were done three years ago. Searches in Github and Packagist under the creator "Shohabbos" finds nothing. The package can be found here: https://github.com/shoxabbos > Repo:oc-customfields-plugin but not in Packagist's searches.
You can try reaching the developer Shoxabbos Olimjonov on his gitHub page:https://github.com/shoxabbos. There are various contact details available. His repository still seems active. Let's hope the gentleman is still ok and just busy writing helpful software tools, and doing so at no cost to you!
I'm still busy installing October and the plugins I feel I may use, and will run a test to find out if the following might assist us in solving the problem. If it does, you or myself can help Shoxabbos and inform him of the updates. If he responds to and allows a Git request, the package might be updated.
The fix seems fairly easy for those that are not averse to tinkering with the plugin code themselves.
Note: It is common sense to first backup a copy of the software you are about to change. If your edits do not work, you can continue from where you were before by replacing the edits you have made.
Here is one reference solution by Arsen, and there are many others as it is a common mistake that went "ignored" with PHP below version 7.4. Stricter coding practice now enforces the rule and will throw errors when using PHP 7.4 and up.
Doing a Stackoverflow search or any browser search for: "Trying to access array offset on value of type null" you might get something like this: https://stackoverflow.com/questions/59336951/message-trying-to-access-array-offset-on-value-of-type-null#59337091
Solution Summary Using your PHP IDE Editor (I like VS Code), open the folder where the plugin resides.
Search for: "$len = $cOTLdata['char_data'] === null ? 0 : count($cOTLdata['char_data']);"
VS Code will give you all the file references where it is found. So, you can open them and do some minor editing.
Copy the file and rename the original to "some-file.php" to "some-file.php.original" Now you can open the original file "some-file.php" and do the search inside the file, then replace the error-causing part to comply with the later versions of PHP.
Some example code found:
public function trimOTLdata(&$cOTLdata, $Left = true, $Right = true) { $len = $cOTLdata['char_data'] === null ? 0 : count($cOTLdata['char_data']); $nLeft = 0; $nRight = 0; //etc</p> }
Change it to the following: "$len = isset($cOTLdata['char_data']) ? count($cOTLdata['char_data']) : 0;"
The example code section will now look as follows: public function trimOTLdata(&$cOTLdata, $Left = true, $Right = true) { $len = isset($cOTLdata['char_data']) ? count($cOTLdata['char_data']) : 0; $nLeft = 0; $nRight = 0; //etc }
Save the edits and run October Again. If it works, you can simply go back to the relevant folder and delete the copies you have made. If not, delete the modified original, rename the copied original name back to its initial name by simply deleting the ".original" part you added earlier. Try another solution after doing a bit of research. Good luck!
1-4 of 4