When I try to print a pdf I get this error:
An uncaught Exception was encountered
Type: DOMException
Message: Invalid Character Error
Filename: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/TreeBuilder.php
Line Number: 3191
Backtrace:
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/TreeBuilder.php
Line: 3191
Function: setAttribute
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/TreeBuilder.php
Line: 1493
Function: insertElement
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/Tokenizer.php
Line: 2456
Function: emitToken
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/Tokenizer.php
Line: 1102
Function: emitToken
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/src/Dompdf.php
Line: 470
Function: parse
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf_helper.php
Line: 26
Function: loadHtml
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/controllers/admin/Estimates.php
Line: 136
Function: pdf_create
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/index.php
Line: 293
Function: require_once
This is my code on line :3191
->
private function insertElement($token, $append = true) {
$el = $this->dom->createElementNS(self::NS_HTML, $token['name']);
if (!empty($token['attr'])) {
foreach ($token['attr'] as $attr) {
if (!$el->hasAttribute($attr['name']) && preg_match("/[^A-Za-z0-9]/u", $attr['name'])) {
$el->setAttribute($attr['name'], $attr['value']);
}
}
}
if ($append) {
$this->appendToRealParent($el);
$this->stack[] = $el;
}
return $el;
}
if you face an error like An uncaught Exception was encountered the best way is, to actually catch the exception, because you get the answer for your error in your Exception
the following code snippet should do what i mean
private function insertElement($token, $append = true) {
try
{
$el = $this->dom->createElementNS(self::NS_HTML, $token['name']);
if (!empty($token['attr'])) {
foreach ($token['attr'] as $attr) {
if (!$el->hasAttribute($attr['name']) && preg_match("/[^A-Za-z0-9]/u", $attr['name'])) {
$el->setAttribute($attr['name'], $attr['value']);
}
}
}
if ($append) {
$this->appendToRealParent($el);
$this->stack[] = $el;
}
return $el;
}
catch (DOMException $e)
{
echo '<strong>Errormessage:</strong>'.$e->getMessage().'<br />';
echo $e->getTraceAsString();
}
}
if you have an error now, you should see the exact information in order to fix this error, something like the following occurs:
Errormessage: Invalid Character Error
#0 [...][...](7): DOMElement->setAttribute('1pro-1', 'someValue')
#1 {main}DOMException Object
Related
I have code that I am trying to update to work with at least PHP version 7.3 and even when I put in a try catch statement I still get a fatal error thrown.
Below is the function that puts Objects into the Session. line causing error: $objects[$i] = $Object;
function findObjectsLIB() {
$objects = ""; $i = 0;
foreach ($_SESSION['Objects'] as $o => $Object) {
$className = get_class($Object);
if (!empty($className)) {
try {
$objects[$i] = $Object;
$i++;
} catch(Exception $err) {
$_SESSION['errors'] .= $err->getMessage();
}
}
}
return $objects;
}
I am getting this error.
PHP Recoverable fatal error: Object of class Extra could not be
converted to string.
How it not being caught?
For one it is strange that it is not being caught and why is it having an issue in 7.3 but not 5.6?
I'm trying to run a command-line task, and my cli.php file is giving me this error:
PHP Notice: Array to string conversion in /var/www/htdocs/classschedule/app/cli.php on line 23
PHP Fatal error: Uncaught RuntimeException: Call to undefined method ::gettaskname() in /var/www/htdocs/classschedule/app/cli.php:23
Stack trace:
#0 /var/www/htdocs/classschedule/app/cli.php(23): Phalcon\Cli\Console->handle(Array)
#1 {main}
thrown in /var/www/htdocs/classschedule/app/cli.php on line 23
Here is my cli.php
include '/var/www/common/dump.php';
require 'config/bootstrap.php';
$DI->get('dispatcher')->setDefaultNamespace('Task');
$DI->get('dispatcher')->setNamespaceName('Task');
$Console = new \Phalcon\CLI\Console();
$Console->setDI($DI);
$arguments = [];
foreach($argv as $k => $arg) {
if($k == 1) {
$arguments['task'] = $arg;
} elseif($k == 2) {
$arguments['action'] = $arg;
} elseif($k >= 3) {
$arguments['params'][] = $arg;
}
}
try{
$Console->handle($arguments); // <-- This is line 23
}
catch(\Phalcon\Exception $e){
echo $e->getMessage();
exit(255);
}
I have no idea why either the Notice or Fatal error are getting generated. This file is almost identical to the cli.php for another app I have, that runs just fine. Even taking out the foreach() still causes the error.
Edit:
Bootstrap.php
Config.php
Solved
Solution:
My DI, Dispatcher, and Router were all MVC versions instead of their CLI equivalents. Changing them fixed the problem - setTask() was expected in the Dispatcher.
Could you please share your config/bootstrap.php file? I tested with:
use Phalcon\Di\FactoryDefault\Cli as DI;
Parameters were read and line 23 was asking for MainTask handler class (no error).
This is the code I tested:
use Phalcon\Loader;
use Phalcon\Di\FactoryDefault\Cli as CliDI;
$DI = new CliDI();
$loader = new Loader();
$loader->registerNamespaces(
[
'Task' => __DIR__ . '/tasks',
]
);
$loader->register();
$Console = new \Phalcon\CLI\Console();
$Console->setDI($DI);
$arguments = [];
foreach($argv as $k => $arg) {
if($k == 1) {
$arguments['task'] = $arg;
} elseif($k == 2) {
$arguments['action'] = $arg;
} elseif($k >= 3) {
$arguments['params'][] = $arg;
}
}
try{
$Console->handle($arguments);
}
catch(\Phalcon\Exception $e){
echo $e->getMessage();
exit(255);
}
And MainTask.php:
namespace Task;
use Phalcon\Cli\Task;
class MainTask extends Task
{
public function mainAction()
{
echo 'This is the default task and the default action' . PHP_EOL;
}
public function testAction(array $params)
{
echo sprintf('hello %s', $params[0]);
echo PHP_EOL;
echo sprintf('best regards, %s', $params[1]);
echo PHP_EOL;
}
}
$Console->handle($arguments); // <-- This is line 23
It seems that this line is expecting a string and you're passing an array.
Maybe phalcon is not handling this case well and can't instantiate some other object on which it tries to call gettaskname on.
my code is generating ssse following error:
Fatal error: Uncaught TypeError: Argument 1 passed to
CI_Exceptions::show_exception() must be an instance of Exception,
instance of Error given, called in
C:\xampp\htdocs\gog\lib\core\Common.php on line 662 and defined in
C:\xampp\htdocs\gog\lib\core\Exceptions.php:190 Stack trace: #0
C:\xampp\htdocs\gog\lib\core\Common.php(662):
CI_Exceptions->show_exception(Object(Error)) #1 [internal function]:
_exception_handler(Object(Error)) #2 {main} thrown in C:\xampp\htdocs\gog\lib\core\Exceptions.php on line 190
The line of the codes described is these:
function _exception_handler(Throwable $exception)
{
$_error =& load_class('Exceptions', 'core');
$_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine());
// Should we display the error?
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
{
$_error->show_exception($exception); //line 662
}
exit(1); // EXIT_ERROR
}
public function show_exception(Exception $exception) //line 190
{
$templates_path = config_item('error_views_path');
if (empty($templates_path))
{
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
}
$message = $exception->getMessage();
if (empty($message))
{
$message = '(null)';
}
if (is_cli())
{
$templates_path .= 'cli'.DIRECTORY_SEPARATOR;
}
else
{
set_status_header(500);
$templates_path .= 'html'.DIRECTORY_SEPARATOR;
}
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
include($templates_path.'error_exception.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
Someone can pinpoint my problem ?
No CodeIgniter version has that _exception_handler() signature. This is what happens when you modify stock framework files.
Download a fresh copy of the latest CodeIgniter and replace yours with it.
You call show_exception(Exception $exception) from within _exception_handler(Throwable $exception). Since the former takes an Exception as argument, you cannot give it a Throwable, as you do in line 662. Exception implements the Throwable interface, but that does not guarantee all Throwables to be Exceptions (e. g. they could be of type Error).
Replace _exception_handler(Throwable $exception) with _exception_handler(Exception $exception), or change show_exception(Exception $exception) to show_exception(Throwable $exception), and change the method bodies accordingly if needed.
I'm trying to find out whether a blob exists or not. When the blob does not exist, my try-catch with Azure's ServiceException isn't being caught at all. I tried following the steps from here.
public function checkBlobExists($path) {
$container = config('azure.storage.container');
$blobClient = ServicesBuilder::getInstance()->createBlobService(config('azure.storage.connection_string'));
try {
$blob = $blobClient->getBlob($container, $path);
return true;
} catch (ServiceException $e) {
return false;
}
return false;
}
This is some of the error stack:
ServiceException in ServiceRestProxy.php line 491:
Fail:
Code: 404
Value: The specified blob does not exist.
details (if any): .
in ServiceRestProxy.php line 491
at ServiceRestProxy::throwIfError(object(Response), array('200', '206')) in ServiceRestProxy.php line 409
at ServiceRestProxy->MicrosoftAzure\Storage\Common\Internal\{closure}(object(ClientException)) in Promise.php line 203
You may not be using the fully qualified exception class name. Try:
//...
} catch (\MicrosoftAzure\Storage\Common\Exceptions\ServiceException $e) {
//...
}
i have php mvc project .
This is my router class.
router class job is include controller in main index page of website.
its work on localhost but when i uploaded on my host not working
what i do ?
<?php
class route
{
function __construct()
{
if(empty($_GET['url']))
{
$url = "index";
}
else
{
$url = $_GET['url'];
}
$url = explode("/",$url);
if(!empty($url[0]))
{
$controllername = "controllers/".$url[0].".php";
if(file_exists($controllername))
{
require($controllername);
$object = new $url[0];
//$object->loadmodel($url[0]);
if(!empty($url[1]))
{
if(method_exists($object,$url[1]))
{
if(!empty($url[2]))
{
$object->$url[1]($url[2]);
}
else
{
$object->$url[1]();
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
}
}
this is my error in error_log
thrown in /home/mogeir/public_html/libs/route.php PHP Notice: Array
to string conversion in /home/mogeir/public_html/libs/route.php on
line 33 PHP Notice: Undefined property: admin::$Array in
/home/mogeir/public_html/libs/route.php on line 33 PHP Fatal error:
Uncaught Error: Function name must be a string in
/home/mogeir/public_html/libs/route.php:33
Use the following function call forms instead - the commented ones are correct alternatives too. See call_user_func and call_user_func_array.
if (!empty($url[2])) {
$object->{$url[1]}($url[2]);
// Alternative 1
// call_user_func(array($object, $url[1]), $url[2]);
// Alternative 2
// call_user_func_array(array($object, $url[1]), array($url[2]));
} else {
$object->{$url[1]}();
// Alternative 1
// call_user_func(array($object, $url[1]));
// Alternative 2
// call_user_func_array(array($object, $url[1]), array());
}
You said:
its work on localhost but when i uploaded on my host not working what i do ?
That has to do with the error reporting activation or with difference in PHP version.