CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • [solved] CDN Tax Receipt extension:cannot pass by reference error
Pages: [1]

Author Topic: [solved] CDN Tax Receipt extension:cannot pass by reference error  (Read 917 times)

seb

  • I’m new here
  • *
  • Posts: 26
  • Karma: 1
  • CiviCRM version: 4.6.4
  • CMS version: Drupal 7/Drupal 8
  • MySQL version: Ver 14.14 Distrib 5.5.44, for debian-linux-gnu
  • PHP version: PHP 5.6.9-0+deb8u1
[solved] CDN Tax Receipt extension:cannot pass by reference error
October 11, 2014, 03:59:14 pm
I get the following error when trying to view a contribution's details (clicking view on a contribution):

 [error] 4172#0: *174385 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Cannot pass parameter 7 by reference in /var/www/mywebsite/drupal/sites/all/modules/civicrm_extensions/org.civicrm.cdntaxreceipts/cdntaxreceipts.functions.inc on line 697"

The content of that file is:

Code: [Select]
function cdntaxreceipts_eligibleAmount( $contributionId ) {
  require_once('CRM/Contribute/DAO/Contribution.php');
  $contribution =  new CRM_Contribute_DAO_Contribution();
  $contribution->id = $contributionId;

  if ( ! $contribution->find( TRUE ) ) {
    CRM_Core_Error::fatal( "CDNTaxReceipts: Could not retrieve details for this contribution" );
  }

  // 1. calculate deductible amount
  $deductibleAmount = $contribution->total_amount - $contribution->non_deductible_amount;

  // 2. allow modules to alter the amount. lowest amount wins.
  $results = CRM_Utils_Hook::singleton()->invoke(1, $contribution, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, 'cdntaxreceipts_eligibleAmount'); ****** line 697

  if (is_array($results)) {
    foreach ( $results as $result ) {
      if ( $result < $deductibleAmount ) {
        $deductibleAmount = $result;
      }
    }
  }

  return $deductibleAmount;
}




I am not familiar with this construct of Civicrm - technically this supposedly worked in civicrm 4.4 - has something changed in that Hook method? I tried looking at the code there but couldn't see quite figure out what function is actually being called that is complaining about a reference

Any pointers as to where to look would be very helpful, as we were relying on this tax-receipt system for our charitable organization :)

Thanks!

EDIT:

The solution as pointed out was to add "CRM_Utils_Hook::$_nullObject," to the ->invoke calls, specifically:

In the file: "/var/mysite/drupal/sites/all/modules/civicrm_extensions/org.civicrm.cdntaxreceipts/cdntaxreceipts.functions.inc" On lines 664, 697 and 896

Tax receipt was issued properly and sent to the correct email after fixing that

« Last Edit: October 13, 2014, 06:20:31 pm by seb »

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: CDN Tax Receipt extension:cannot pass by reference error
October 13, 2014, 11:44:07 am
It looks like the signature of invoke() changed in 4.5:

Code: [Select]
$ git diff origin/4.4 origin/4.5 -- CRM/Utils/Hook.php
...
 abstract function invoke($numParams,
-    &$arg1, &$arg2, &$arg3, &$arg4, &$arg5,
+    &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
     $fnSuffix
   );

In 4.5, it probably requires an extra CRM_Utils_Hook::$_nullObject for $arg6.

If you don't want to publish separate builds for 4.4/4.5, then it probably needs to do a version check. Maybe something along these lines (untested):

Code: [Select]
if (version_compare(CRM_Utils_System::version(), '4.5', '<'))
  $results = CRM_Utils_Hook::singleton()->invoke(1, $contribution, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, 'cdntaxreceipts_eligibleAmount');
} else {
  $results = CRM_Utils_Hook::singleton()->invoke(1, $contribution, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, 'cdntaxreceipts_eligibleAmount');
}

seb

  • I’m new here
  • *
  • Posts: 26
  • Karma: 1
  • CiviCRM version: 4.6.4
  • CMS version: Drupal 7/Drupal 8
  • MySQL version: Ver 14.14 Distrib 5.5.44, for debian-linux-gnu
  • PHP version: PHP 5.6.9-0+deb8u1
Re: CDN Tax Receipt extension:cannot pass by reference error
October 13, 2014, 06:01:43 pm
Ah thank you, that might just solve my problem..

I am an end-user of the CDNTaxReceipt extension, and we've come to rely on this extension but it appears that it wasn't updated to 4.5 yet :(

 

msn

  • I post frequently
  • ***
  • Posts: 152
  • Karma: 6
  • Please talk to the other site
Re: [solved] CDN Tax Receipt extension:cannot pass by reference error
November 08, 2014, 06:43:01 pm
Thanks, I used the if solution, solves the update 4.5

KarinG

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
  • CiviCRM version: 4+
  • CMS version: Drupal 6 / 7
  • MySQL version: MariaDB
  • PHP version: 5.3/5.4/5.5
Re: [solved] CDN Tax Receipt extension:cannot pass by reference error
January 29, 2015, 01:38:18 pm
Thanks Tim - I totally missed this - All our (major) CDN non-profits have decided to stay on 4.4.x LTS at least until after this year's tax receipt season (ends Feb. 28) - so it fell off the radar - sorry about that!

In addition to the delta in how we now call our hooks - CRM_hook_utils - my white/red maple leaf is MIA - will have to dig that up.

Will have a 4.5.x release of CDN TaxReceipts soon - for people to test.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • [solved] CDN Tax Receipt extension:cannot pass by reference error

This forum was archived on 2017-11-26.