We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16903
    • 39 Posts
    Aloa,

    just updated to 1.8.2 and now i get always an error:
    htmlspecialchars() expects at most 3 parameters, 4 given


    I reduce my params in order to find the problem, but without success.
    At the moment my call looks like:
    [!AjaxSearch? &ajaxSearch=`0` &AS_landing= `32`!]


    Any ideas?
    Thanks in advance.
    Leif
      • 5811
      • 1,717 Posts
      htmlspecialchars() expects at most 3 parameters, 4 given
      Where did you get this error ? In which file, which number code line ?
        • 22851
        • 805 Posts
        While it is very useful, the fourth parameter, double_encode, is only available for php version 5.2.3 and onwards. All core MODx code that I have seen avoids it, probably for that reason.

        I encountered this problem some time ago when I wrote some code for an unrelated application using the four parameter version and then found out that an old version of php was being used on the final system. I tried to solve the problem by using the Pear compatibility library but a compatibility layer wasn’t available for htmlspecialchars at that time. In the end I updated the code to remove the fourth parameter. Nevertheless, I put in a request for it to be added to the Pear compatibility library and I understand that it has been added since then.

        So, rather than modifying AjaxSearch, you could try using the Pear compatibilty layer for htmlspecialchars. This will allow you to use the fourth parameter with older versions of php.

        I haven’t upgraded to AjaxSearch 1.8.2 yet on all MODx installations, but thanks for the heads up on this: I too will have to do the same for one of my installations where I am unable to upgrade php.

          YAMS: Yet Another Multilingual Solution for MODx
          YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
          Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
          • 5811
          • 1,717 Posts
          @Rohal,

          To prevent the use of the fourth parameter you could replace in file classes/search.class.inc.php the line #145:
                $searchString = htmlspecialchars($searchString, ENT_COMPAT, $pgCharset, False);

          by:
                if ($this->isPhp5) $searchString = htmlspecialchars($searchString, ENT_COMPAT, $pgCharset, False);
                else $searchString = htmlspecialchars($searchString, ENT_COMPAT, $pgCharset);


          Do this update and let me know the results.
            • 16903
            • 39 Posts
            Sorry, doesn’t worked:

            Error: htmlspecialchars() expects at most 3 parameters, 4 given
            Error type/ Nr.: Warning - 2
            Line: 145
            Line 145 source: if ($this->isPhp5) $searchString = htmlspecialchars($searchString, ENT_COMPAT, $pgCharset, False);
              • 22851
              • 805 Posts
              Attached is the htmlspecialchars function from the pear PHP compatibility library that you could include with ajaxSearch to get it to work.
                YAMS: Yet Another Multilingual Solution for MODx
                YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                • 16903
                • 39 Posts
                How should i include that with AjaxSearch?
                  • 22851
                  • 805 Posts
                  I think that if you rename the file from my previous post as htmlspecialchars.php, place it next to search.class.inc.php in the classes subdirectory and then add the line

                  include('htmlspecialchars.php');


                  at the beginning of the original search.class.inc.php file it will probably just work. If not then you’ll have to read the PHP_compat documentation I’m afraid. Sorry I haven’t got time to do that myself this second.
                    YAMS: Yet Another Multilingual Solution for MODx
                    YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                    Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                    • 5811
                    • 1,717 Posts
                    Rohal could you rename your previous classes/search.class.inc.php file, dowload the zip file attached and drop this new version of classes/search.class.inc.php in the classes folder.
                    I have added the php_compat_htmlspecialchars function which should work with php > 4.0. Let me know the results.
                    If it is ok, I will update the release 1.8.2 to include this fix.

                    The fourth parameter is required. See this post for more information.

                    [EDIT: Attached file removed]
                      • 16903
                      • 39 Posts
                      PHP error debug
                        Error: 	htmlspecialchars() expects parameter 3 to be string, NULL given	 
                        Error type/ Nr.: 	User Warning - 512	 
                        File: 	... /assets/snippets/ajaxSearch/classes/search.class.inc.php	 
                        Line: 	1906	 
                        Line 1906 source: 	gettype($charset) . ' given', E_USER_WARNING); 


                      Sorry, still doesn’t work... :-(