Title: Can&#8217;t use function return value in write context (PHP 7.2)
Last modified: March 17, 2019

---

# Can’t use function return value in write context (PHP 7.2)

 *  Resolved [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/)
 * Hi,
 * I am trying to add your code:
 * add_action( ‘cf7_2_post_status_post’, ‘publish_new_post’,10,3);
    /** * Function
   to change the post status of saved/submitted posts. * [@param](https://wordpress.org/support/users/param/)
   string $status the post status, default is ‘draft’. * [@param](https://wordpress.org/support/users/param/)
   string $ckf7_key unique key to identify your form. * [@param](https://wordpress.org/support/users/param/)
   array $submitted_data complete set of data submitted in the form as an array 
   of field-name=>value pairs. * [@return](https://wordpress.org/support/users/return/)
   string a valid post status (‘publish’|’draft’|’pending’|’trash’) */ function 
   publish_new_post($status, $ckf7_key, $submitted_data){ /*The default behaviour
   is to save post to ‘draft’ status. If you wish to change this, you can use this
   filter and return a valid post status: ‘publish’|’draft’|’pending’|’trash’*/ 
   return ‘publish’; }
 * I am getting an error:
    Can’t use function return value in write context line
   193, file: wp-content/plugins/post-my-contact-form-7/public/class-cf7-2-post-
   public.php
 * I noticed people had similar problems with PHP5*, I am using 7.2. Am I doing 
   sth wrong?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcant-use-function-return-value-in-write-context-php-7-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/page/2/?output_format=md)

 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11323969)
 * PHP is 7.2.3. Tried downgrading to 7.1 – the same. It turns out I don’t even 
   have to add any code. When I open editor and just click save – I get an error.
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11355848)
 * Hi [@psubraty](https://wordpress.org/support/users/psubraty/)
 * sorry for the delayed response, I went through a bout of sickness and lots of
   work to catch up.
 * That’s odd, this [error](https://stackoverflow.com/questions/17139264/cant-use-function-return-value-in-write-context)
   only happens for PHP version < 5.5
 * > PHP is 7.2.3. Tried downgrading to 7.1 – the same.
 * Are you sure your server is using php 7? it is possible that you have v7 installed,
   but if you do not configure your apache server to use it, it is quite possible
   that it is using v5.4.
 * Follow these [instructions](https://www.namecheap.com/support/knowledgebase/article.aspx/9397/2219/how-to-check-php-version-and-configuration)
   to double check your php version.
 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11355857)
 * Yes, I triple checked. Also right now using this method You pointed. PHP Version
   7.1.15
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11355863)
 * mmmh, that’s odd. I am using php 7 on my local machine. I will give it a try 
   to see if I can reproduce the error.
 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11416960)
 * Hi. Were You able to find the problem?
    Psubraty
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11420005)
 * No. Did you check you php with `php_info()` or using the command line `php -version`?
 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11422591)
 * As I sad, I triple checked. Including all the methodes mentioned in the link 
   You provided. I really know the version of PHP on my server. I can give You an
   access to the wordpress to test it.
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11423793)
 * It’s very strange, this is an error that occurs with php versions prior to v7.
 * So the only issue can I see is that your php is somewhat referring to an older
   library… maybe your installation of pho had an issue and some libraries were 
   not upgraded to v7?
 * My suggestion would be to upgrade your server to v7.3 (the lastest version) or
   at least try to re-install your current version.
 * If this is not possible then the only solution is to hack the plugin code to 
   make it compatible with your specific setup, in which case I can tell you which
   lines to change to make it work.
 * let me know what you want to do.
 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11425271)
 * This is a shared server, I’ll ask my hosting provider about the possible problems
   You mentioned. Meanwhile it would be great if You could provide the code to be
   replaced 🙂
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11478788)
 * HI there, I realised I never got back to your with the code…
 * Replace the lines 188-193 which have this code,
 *     ```
           $pattern = get_shortcode_regex();
   
           // if shortcode 'book' exists
           if ( preg_match_all( '/'. $pattern .'/s', $content, $matches )
             && array_key_exists( 2, $matches )
             && !empty(array_intersect( $shortcodes, $matches[2] )) )  {
       ```
   
 * with the following lines of code,
 *     ```
           $pattern = get_shortcode_regex();
           $search_shortcodes = array_intersect( $shortcodes, $matches[2] );
           // if shortcode 'book' exists
           if ( preg_match_all( '/'. $pattern .'/s', $content, $matches )
             && array_key_exists( 2, $matches )
             && !empty($search_shortcodes) )  {
       ```
   
 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11505359)
 * Hi,
 * I am able to save this change, but I am getting an error while loading any page:
 * Warning: array_intersect(): Argument #2 is not an array in /home/users/woof/public_html/
   ogrod.ptakipolskie.pl/wp-content/plugins/post-my-contact-form-7/public/class-
   cf7-2-post-public.php on line 189
 * Now I can’t go back to old code neither. This time I get an error while trying
   to save code:
 * Line 193: && !empty(array_intersect( $shortcodes, $matches[2] )) ) {
    Can’t use
   function return value in write context
    -  This reply was modified 7 years, 1 month ago by [psubraty](https://wordpress.org/support/users/psubraty/).
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11507751)
 * ah, yes, I see my mistake, apologies for this, please replace with the following
   lines instaed,
 *     ```
       $pattern = get_shortcode_regex();
       $isMatch = preg_match_all( '/'. $pattern .'/s', $content, $matches );
       if($isMatch) $search_shortcodes = array_intersect( $shortcodes, $matches[2] );
       // if shortcode 'book' exists
       if ( $isMatch && array_key_exists( 2, $matches ) && !empty($search_shortcodes) )  {
       ```
   
 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11512821)
 * works like charm, thank You!
 *  Thread Starter [psubraty](https://wordpress.org/support/users/psubraty/)
 * (@psubraty)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11512831)
 * oh, one more thing. Will this change in code be implemented in “standard”? If
   not, it will get updated after next patch and I will have to switch code manually?
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/#post-11520476)
 * No i don’t plan to put it as std. The only people who have faced a similar issue(
   in this plugin or other plugins i maintain) where all running php 5.6 or lower.
   The issue systematically went away when users upgraded to php 7.
 * So i am still not sure why you’re facing this issue with php 7.2. It is possible
   the php installation was incomplete and some libraries are from5.6.
 * Could you test your installation on a different server running php 7?

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/page/2/?output_format=md)

The topic ‘Can’t use function return value in write context (PHP 7.2)’ is closed
to new replies.

 * ![](https://ps.w.org/post-my-contact-form-7/assets/icon-256x256.png?rev=1985682)
 * [Post My CF7 Form](https://wordpress.org/plugins/post-my-contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-my-contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-my-contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/post-my-contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-my-contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-my-contact-form-7/reviews/)

 * 17 replies
 * 2 participants
 * Last reply from: [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/cant-use-function-return-value-in-write-context-php-7-2/page/2/#post-11520770)
 * Status: resolved