PHP Warning: Declaration

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
vBBANKs
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Apr 27, 2018 9:51 am

Fri Apr 27, 2018 10:20 am

I am trying to fix all these errors but no matter what i do it doesnt work. Please Help

I am using Mamp with php5.4 ( yea i know )

Code: Select all

PHP Strict Standards: Declaration of FPDF::SetDrawColor() should be compatible with tFPDF::SetDrawColor($r, $g = NULL, $b = NULL) in /Applications/MAMP/htdocs/squid/lib/card_pdf.php on line 11

Code: Select all

 <?php


  $cwd = getcwd();

  chdir( dirname(__FILE__) );

  require 'tfpdf/tfpdf.php';

class FPDF extends tFPDF 
{
    private $_encoding = 'UTF-8';

    var $angle=0;

    public function Rotate($angle, $x=-1, $y=-1)
    {
        if($x==-1)
            $x=$this->x;
        if($y==-1)
            $y=$this->y;
        if($this->angle!=0)
            $this->_out('Q');
        $this->angle=$angle;
        if($angle!=0)
        {
            $angle*=M_PI/180;
            $c=cos($angle);
            $s=sin($angle);
            $cx=$x*$this->k;
            $cy=($this->h-$y)*$this->k;
            $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm', $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
        }
    }

vBBANKs
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Apr 27, 2018 9:51 am

Fri Apr 27, 2018 3:41 pm

There has to be someone here that can fix this...

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 719
Joined: Mon Feb 22, 2016 5:52 pm

Fri Apr 27, 2018 4:10 pm

There is a parameter mismatch between the classes. You need to re-write one or both of the functions:

Code: Select all

FPDF::SetDrawColor()
tFPDF::SetDrawColor($r, $g = NULL, $b = NULL)

vBBANKs
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Apr 27, 2018 9:51 am

Fri Apr 27, 2018 4:17 pm

So i can replace this code :

Code: Select all

class FPDF extends tFPDF 
with this:

Code: Select all

FPDF::SetDrawColor()
or

Code: Select all

tFPDF::SetDrawColor($r, $g = NULL, $b = NULL)

vBBANKs
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Apr 27, 2018 9:51 am

Sat Apr 28, 2018 7:58 am

Please help with this.. or help with this syntax error here:

Code: Select all

<?php


$cwd = getcwd();

chdir( dirname(__FILE__) );

require 'tfpdf/tfpdf.php';

class FPDF extends tFPDF {}
{
	private $_encoding = 'UTF-8';

	var $angle=0;

	public function Rotate($angle, $x=-1, $y=-1)
	{
		if($x==-1)
		    $x=$this->x;
		if($y==-1)
		    $y=$this->y;
		if($this->angle!=0)
		    $this->_out('Q');
		$this->angle=$angle;
		if($angle!=0)
		{
		    $angle*=M_PI/180;
		    $c=cos($angle);
		    $s=sin($angle);
		    $cx=$x*$this->k;
		    $cy=($this->h-$y)*$this->k;
		    $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm', $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
		}
	}


	/*
		Author	: Fernando Herrero
		Mail	: fherrero[at]noticiasdenavarra.com
		Program	: pdf-cmyk.php
		License	: GPL v2
		Description: Allow to use CMYK color space:
					 SetDrawColor() => Set draw color to black
					 SetDrawColor(int gray) => value in % (0 = black, 100 = white)
					 SetDrawColor(int red, int green, int blue) => 0 to 255
					 SetDrawColor(int cyan, int magenta, int yellow, int black) => values in % (0 to 100)
					 SetFillColor and SetTextColor same as SetDrawColor
		Date	   : 2004-01-22
	*/
	public function SetDrawColor() {
		//Set color for all stroking operations
		switch(func_num_args()) {
			case 1:
				$g = func_get_arg(0);
				$this->DrawColor = sprintf('%.3F G', $g / 100);
				break;
			case 3:
				$r = func_get_arg(0);
				$g = func_get_arg(1);
				$b = func_get_arg(2);
				$this->DrawColor = sprintf('%.3F %.3F %.3F RG', $r / 255, $g / 255, $b / 255);
				break;
			case 4:
				$c = func_get_arg(0);
				$m = func_get_arg(1);
				$y = func_get_arg(2);
				$k = func_get_arg(3);
				$this->DrawColor = sprintf('%.3F %.3F %.3F %.3F K', $c / 100, $m / 100, $y / 100, $k / 100);
				break;
			default:
				$this->DrawColor = '0 G';
		}
		if($this->page > 0)
			$this->_out($this->DrawColor);
	}

	public function SetFillColor() {
		//Set color for all filling operations
		switch(func_num_args()) {
			case 1:
				$g = func_get_arg(0);
				$this->FillColor = sprintf('%.3F g', $g / 100);
				break;
			case 3:
				$r = func_get_arg(0);
				$g = func_get_arg(1);
				$b = func_get_arg(2);
				$this->FillColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
				break;
			case 4:
				$c = func_get_arg(0);
				$m = func_get_arg(1);
				$y = func_get_arg(2);
				$k = func_get_arg(3);
				$this->FillColor = sprintf('%.3F %.3F %.3F %.3F k', $c / 100, $m / 100, $y / 100, $k / 100);
				break;
			default:
				$this->FillColor = '0 g';
		}
		$this->ColorFlag = ($this->FillColor != $this->TextColor);
		if($this->page > 0)
			$this->_out($this->FillColor);
	}

	public function SetTextColor() {
		//Set color for text
		switch(func_num_args()) {
			case 1:
				$g = func_get_arg(0);
				$this->TextColor = sprintf('%.3F g', $g / 100);
				break;
			case 3:
				$r = func_get_arg(0);
				$g = func_get_arg(1);
				$b = func_get_arg(2);
				$this->TextColor = sprintf('%.3F %.3F %.3F rg', $r / 255, $g / 255, $b / 255);
				break;
			case 4:
				$c = func_get_arg(0);
				$m = func_get_arg(1);
				$y = func_get_arg(2);
				$k = func_get_arg(3);
				$this->TextColor = sprintf('%.3F %.3F %.3F %.3F k', $c / 100, $m / 100, $y / 100, $k / 100);
				break;
			default:
				$this->TextColor = '0 g';
		}
		$this->ColorFlag = ($this->FillColor != $this->TextColor);
	}

	/*
	 * END pdf-cmyk.php by Fernando Herrero
	 */



	public static function strip ($dirty=array())
	{
		if (is_array($dirty))
		{
			foreach ($dirty as $key=> $dirtyValue)
				$clean[$key] = self::strip($dirtyValue);
		} else {
			$double	= substr_count($dirty, "\"") == substr_count($dirty, "\\\"");
			$single	= substr_count($dirty, "'") == substr_count($dirty, "\\'");
			$clean	= self::encodeString( ($double && $single)? stripslashes($dirty): $dirty );
		}
		return $clean;
	}
	
	
	public static function encode_string ($string)
	{
		# create a utf32 string for comparison
		$utf32_string	= mb_convert_encoding($string, 'UTF-32', 'UTF-8');

		# convert the utf32 string back to utf8, if it matches then the passed string is utf8
		if ($string === mb_convert_encoding($utf32_string , 'UTF-8', 'UTF-32'))
		{
			return $string;
		# otherwise it's not and should be converted
		} else {
			return mb_convert_encoding($string, 'UTF-8');
		}
	}

	public function NbLines($w, $string)
	{
		$string = self::encode_string($string);

		if ($this->FontSize < 0)
		{
			return 0;
		}

		$font_widths	= $this->CurrentFont['cw'];

		$max_width		= ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;

		$string			= str_replace("\r", '', $string);

		$string_length	= mb_strlen($string, $this->_encoding);

		if (mb_substr($string, $string_length-1, 1, $this->_encoding) === "\n")
		{
			$string = mb_substr($string, 0, $string_length-1, $this->_encoding);
		}

		$last_space		= -1;
		$char_pos		= 0;
		$j				= 0;
		$line_length	= 0;
		$line_count		= 1;

		while($char = mb_substr($string, $char_pos, 1, $this->_encoding))
		{
			list(,$char_code) = unpack('N', mb_convert_encoding($char, 'UCS-4BE', $this->_encoding));

			$char_width = isset($font_widths[$char_code])? $font_widths[$char_code]: 0;

			if($char === "\n")
			{
				$char_pos++;
				$line_count++;
				$last_space		= -1;
				$j				= $char_pos;
				$line_length	= 0;

				continue;
			}

			if($char === ' ')
			{
				$last_space = $char_pos;
			}

			$line_length += $char_width;

			if($line_length > $max_width)
			{
				if($last_space == -1)
				{
					($char_pos == $j)  &&  $char_pos++;

				} else {

					$char_pos = $last_space+1;
				}

				$last_space		= -1;
				$j				= $char_pos;
				$line_length	= 0;
				$line_count++;

				continue;
			}

			$char_pos++;
		}
		return $line_count;
	}
}

require 'FPDI-1.4/fpdi.php';

chdir( $cwd );



chorn
php-forum Fan User
php-forum Fan User
Posts: 558
Joined: Fri Apr 01, 2016 2:18 am

Sun Apr 29, 2018 4:23 am

Just use an online validator like 3v4l.org for syntax error check.

vBBANKs
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Apr 27, 2018 9:51 am

Sun Apr 29, 2018 8:08 am

I did use that :

Code: Select all

private $_encoding = 'UTF-8';

vBBANKs
New php-forum User
New php-forum User
Posts: 6
Joined: Fri Apr 27, 2018 9:51 am

Sun May 13, 2018 8:58 am

Here are the latest errors:
[11-May-2018 23:57:46 America/New_York] PHP Warning: include_once(/squid/lib/font/): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 507
[11-May-2018 23:57:46 America/New_York] PHP Warning: include_once(): Failed opening '/squid/lib/font/' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.4.45/lib/php') in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 507
[11-May-2018 23:57:46 America/New_York] PHP Fatal error: Class 'TTFontFile' not found in /Applications/MAMP/htdocs/squid/lib/tfpdf.php on line 508

cant figure this out

here is the code
if ($uni) {
if (defined("_SYSTEM_TTFONTS") && file_exists(_SYSTEM_TTFONTS.$file )) { $ttfilename = _SYSTEM_TTFONTS.$file ; }
else { $ttfilename = $this->_getfontpath().'unifont/'.$file ; }
$filename = $file;
$filename =str_replace(' ','',$filename );
$filename =str_replace('-','',$filename );
$unifilename = $this->_getfontpath().'unifont/'.strtolower(substr($filename ,0,(strpos($filename ,'.'))));
$diff = '';
$enc = '';
if (file_exists($unifilename.'.mtx.php')) {
include($unifilename.'.mtx.php');
}
if (!isset($type) || $type != "TrueTypesubset") {
include_once($this->_getfontpath().'unifont/ttfonts.php');
line 507>>> $ttf = new TTFontFile();
$ttf->getMetrics($ttfilename);
$cw = $ttf->charWidths;
$type = "TrueTypesubset";
$name = preg_replace('/ /','',$ttf->fullName);
$desc= array('Ascent'=>round($ttf->ascent),
'Descent'=>round($ttf->descent),
'CapHeight'=>round($ttf->capHeight),
'Flags'=>$ttf->flags,
'FontBBox'=>'['.round($ttf->bbox[0])." ".round($ttf->bbox[1])." ".round($ttf->bbox[2])." ".round($ttf->bbox[3]).']',
'ItalicAngle'=>$ttf->italicAngle,
'StemV'=>round($ttf->stemV),
'MissingWidth'=>round($ttf->defaultWidth));
$up = round($ttf->underlinePosition);
$ut = round($ttf->underlineThickness);
//Generate metrics .php file
$s='<?php'."\n";
$s.='$type=\''.$type."';\n";
$s.='$name=\''.$name."';\n";
$s.='$desc='.var_export($desc,true).";\n";
$s.='$up='.$up.";\n";
$s.='$ut='.$ut.";\n";
$s.='$cw='.var_export($cw,true).";\n";
$s.="?>\n";
if (is_writable($this->_getfontpath().'unifont')) {
$fh = fopen($unifilename.'.mtx.php',"w");
fwrite($fh,$s,strlen($s));
fclose($fh);
}

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 719
Joined: Mon Feb 22, 2016 5:52 pm

Sun May 13, 2018 11:50 am

PHP can't find 'ttfonts.php', your path is wrong.

Post Reply