September 10, 2013
Using Anonymous functions in php 5.2
Raj’s Question:
I know Anonymous functions are supported only in php5.3 and above.
But due to some difficult circumstances , I have to use the code below in php 5.2
Can anybody please help me to convert this to work in php 5.2
====================================================
$fn = function($points) use ($pdf) {
$op = 'f';
$h = $pdf->h;
$k = $pdf->k;
$points_string = '';
for($i=0; $i < 8; $i+=2){
$points_string .= sprintf('%.2F %.2F', $points[$i]*$k,($h-$points[$i+1])*$k);
$points_string .= $i ? ' l ' : ' m ';
}
$pdf->_out($points_string . $op);
};
====================================================
The full code is available at
http://barcode-coder.com/download/php-barcode-2.0.3.zip
I have now tried for hours with create_function but somehow can get this to work.
Please help me to adapt this to php5.2
Also how to duplicate the functionality of use in php5.2
ie how to pass a var like $pdf to create_function
Just sent the variable as parameter:
function fn($points, $pdf) {
$op = 'f';
$h = $pdf->h;
$k = $pdf->k;
$points_string = '';
for($i=0; $i < 8; $i+=2){
$points_string .= sprintf('%.2F %.2F', $points[$i]*$k,($h-$points[$i+1])*$k);
$points_string .= $i ? ' l ' : ' m ';
}
$pdf->_out($points_string . $op);
};