this must be a very stupid question, but i have been searching it's answer and can't find the problem... I've got some trouble while trying to display a smarty template, i was using an older version of smarty and everything worked fine, yet i updated to smarty 3 and i got an exception, it's message saying:
Call of unknown method 'display'.
This is my code:
Index.php
require_once './GeneralFunctions.php';
$smartyVariables = getSmartyVariablesToAssign();
tryToDisplaySmartyTemplate('Index.tpl', $smartyVariables);
function getSmartyVariablesToAssign() {
$userAndOrPasswordError = $_GET['userAndOrPasswordError'];
return array(
'userAndOrPasswordError' => $userAndOrPasswordError
);
}
GeneralFunctions.php
require_once './smarty/libs/Smarty.class.php';
function tryToDisplaySmartyTemplate($templateName, $variablesToAssign = null) {
try {
$mySmarty = callSmarty();
assignSmartyVariables($mySmarty, $variablesToAssign);
$mySmarty->display($templateName);
} catch (Exception $exc) {
showCatchedExceptionTraceAndMessage($exc);
}
}
function callSmarty() {
$mySmarty = new Smarty();
$mySmarty->template_dir = 'smarty/templates';
$mySmarty->compile_dir = 'smarty/templates_c';
$mySmarty->config_dir = 'smarty/config';
$mySmarty->cache_dir = 'smarty/cache';
return $mySmarty;
}
function assignSmartyVariables($mySmarty, $variablesToAssign) {
foreach ($variablesToAssign as $key => $value) {
$mySmarty->assign($key, $value);
}
}
function showCatchedExceptionTraceAndMessage(Exception $exc) {
echo "OcurriĆ³ un error desconocido, por favor, notifique al departamento de sistemas.",
"<br>",
"<br>",
$exc->getTraceAsString(),
"<br>",
"<br>",
$exc->getMessage();
}
I've been investigating, and all i know until now is the existence of a smarty method: testInstall()
Which gives the following info:
Smarty Installation test... Testing template directory...
C:\xampp\htdocs\develop\Registro_de_Tramites\smarty\templates is OK.
Testing compile directory...
C:\xampp\htdocs\develop\Registro_de_Tramites\smarty\templates_c is OK.
Testing plugins directory...
C:\xampp\htdocs\develop\Registro_de_Tramites\smarty\libs\plugins is
OK. Testing cache directory...
C:\xampp\htdocs\develop\Registro_de_Tramites\smarty\cache is OK.
Testing configs directory...
C:\xampp\htdocs\develop\Registro_de_Tramites\smarty\config is OK.
Testing sysplugin files... FAILED: files missing from libs/sysplugins:
smarty_internal_extension_codeframe.php,
smarty_internal_extension_config.php,
smarty_internal_extension_defaulttemplatehandler.php,
smarty_internal_filter_handler.php,
smarty_internal_function_call_handler.php,
smarty_internal_get_include_path.php.
Testing plugin files... ... OK
Tests complete.
I've separated the only FAILED i've got from the rest. It seems libs/sysplugins folder is missing some php files, but downloading it all over again from smarty releases, just gives the same files i have...
To install it, i just copy libs folder into my project, inside "smarty" folder.
Hope to get some help :/
I knew it was a stupid question... by reinstalling smarty 3 it all worked, you see, it seems there was a problem with tortoiseSVN which (who knows why) didn't upload all smarty files properly the first time.
Strange though, that the files missing weren't the ones testInstall() was talking about...
Anyway, if any of you guys have the same problem, try reinstalling smarty first.
Related
My php project is now working on Apache with mod_php. I want to open OpCache to accelerate my code. But I'm worry about if it's safe to update the code.
The validate_timestamps should be 0. Because the code may expire when you update new version, and this can make the code of new version call the code of old version.
But even if I set validate_timestamps=0, this can also happen. When I update the code file, one of the code file that hasn't been cached is called. And thus this code file is in new version while the caller is in old version. Maybe I can load all the code files into cache before the server start?
If I find a way to make sure all the files in the project dir are loaded into cache before the Apache start to serve requests, I can update new version code first, and then clear all the OpCache. But does it have an impact on those working requests? Will they run an old logic and then be switch into a new one?
Besides, how to clear all the OpCache in an atom time? If it takes time to clear all the OpCache, the problem is still there, right?
Can anyone help me? Thank you very much!
Let me show an example.
I have two files on my directory, and the Apache's working directory is also there.
The entry file is index.php.
<?php
echo "verson 1: index";
// do some work
sleep(1);
// not all APIs will call this library
// I just use rand to represent a probability
if (rand(0,100) == 1) {
require_once BASEPATH.'lib.php';
t = new Tester();
t->func1();
}
And the other php file is lib.php.
<?php
echo "---- version 1: lib";
class Tester {
function __construct() {
echo "---- new Tester in lib.php";
}
public function func1() {
echo "---- Tester.func1()";
}
}
Now I'm going to upload my new version code.
In the new version, I declare a new function func2() in Tester and delete the old function func1(). I call it in the index.php.
index.php
<?php
echo "version 2: index";
// do some work
sleep(1);
// not all APIs will call this library
// I just use rand to represent a probability
if (rand(0,100) == 1) {
require_once BASEPATH.'lib.php';
t = new Tester();
t->func2();
}
lib.php
<?php
echo "---- version 2: lib";
class Tester {
function __construct() {
echo "---- new Tester in lib.php";
}
public function func2() {
echo "---- Tester.func2()";
}
}
I close the OpCache. I upload the index.php first and then the other one lib.php. At the moment between I finish to upload the index.php and begin to upload lib.php, a request is running into the "rand case". Then I will get an error about "func2() not defined", because the lib.php is still the old one at that time.
If I open the OpCache, it's the same if I don't set validate_timestamps to 0.
After I set validate_timestamps to 0, the opcode will not expire. So I must call opcache_reset manually after I finish to upload index.php and lib.php. At that moment, a request also runs into the "rand case". If the opcache_reset operation takes a period of time, and it doesn't block the request running, the error "func2() not defined" may also occur.
How to make all the requests safe when I upgrade my code version?
I recently finished building my site using code igniter on WAMP local server and tested it on a shared hosting server (from Namecheap). Then I got VPS hosting plan (from iPage) and uploaded the files and did the necessary configs. However, I got this error when I tried accessing the site:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function ctype_digit()
Filename: /home/eastngco/public_html/system/core/Security.php
Line Number: 600
Problem is, the suspect file, Security.php, is a code igniter system file which I never messed with (everything I wrote was within the application folder). Below is a code snippet around the line in Security.php causing the error:
/**
* Get random bytes
*
* #param int $length Output length
* #return string
*/
public function get_random_bytes($length)
{
if (empty($length) OR ! ctype_digit((string) $length))
{
return FALSE;
}
if (function_exists('random_bytes'))
{
try
{
// The cast is required to avoid TypeError
return random_bytes((int) $length);
}
catch (Exception $e)
{
// If random_bytes() can't do the job, we can't either ...
// There's no point in using fallbacks.
log_message('error', $e->getMessage());
return FALSE;
}
}
// Unfortunately, none of the following PRNGs is guaranteed to exist ...
if (defined('MCRYPT_DEV_URANDOM') && ($output = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)) !== FALSE)
{
return $output;
}
if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE)
{
// Try not to waste entropy ...
is_php('5.4') && stream_set_chunk_size($fp, $length);
$output = fread($fp, $length);
fclose($fp);
if ($output !== FALSE)
{
return $output;
}
}
if (function_exists('openssl_random_pseudo_bytes'))
{
return openssl_random_pseudo_bytes($length);
}
return FALSE;
}
I have no idea what random bytes or ctype_digit() means!
I did some digging on the web to see if a similar problem (and its solution) would pop, but nothing did. I need help fixing this please.
If it means anything, the PHP version that comes with my hosting plan is version 7, and I have SSL.
Ipage has a support page to enable the ctype extension, please read this article, using code igniter and PHP: 7.4.10, I receive this error message: Call to undefined function ctype_digit().
Enabling this extension in Ipage the problem was solved in my case.
Article:
https://www.ipage.com/help/article/how-to-enable-ctype-so-extensions-in-php-ini
Looks like your provider might have explicitly disabled those types of functions. It should be enabled by default. Try contacting your provider for some support on enabling these, or reinstalling PHP without that flag turned off.
http://us2.php.net/manual/en/ctype.installation.php
Additionally, you could try and inspect a phpinfo() page to confirm whether ctypes are enabled or not. It seems weird that they would turn it off, so this would help figure out if this is part of the issue.
i work with token (COM Object) , in java Script all things is okay . my problem is creating a object from it in php.
this is the code :
try {
// flag 1
$verifier = new COM("pkiactivex.Verifier") or die("Couldn't create the COM Component");
// flag 2
}
catch(com_exception $e)
{
//flag 3
}
first i should say this code work in another local system in wampp and i have xampp and i don't think it's because of xampp or wampp but i think maybe a module is missing. about code in my system code run until flag 1 and even its don't go to exception and flag 3 it's go no where , even i see a blank page with no error !!
i know it's not a php error and i put the code just for more detail!
Got a bit of an issue with Modx and latest version of PHP.
It's a very old version of Modx (don't ask - I have exactly the same thoughts, wasn't in my control). The site is working fine on PHP 5.2.
The problem is the web host is upgrading to PHP 5.4 - as a result the site breaks completely. The one issue I can't get a solution for is the use of eval within manager/includes/document.parser.class.inc.php under "evalSnippet()" function where it calls depreciated eval() function.
I've looked at possibliity of upgrading Modx to latest which is 1.0.9, however this still uses eval() -> even though it explicity states this version supports PHP 5.4. Below is the code:
function evalSnippet($snippet, $params) {
$etomite= $modx= & $this;
$modx->event->params= & $params; // store params inside event object
if (is_array($params)) {
extract($params, EXTR_SKIP);
}
ob_start();
$snip= eval ($snippet);
$msg= ob_get_contents();
ob_end_clean();
if ((0<$this->config['error_reporting']) && isset($php_errormsg))
{
$error_info = error_get_last();
if($error_info['type']===2048 || $error_info['type']===8192) $error_type = 2;
else $error_type = 3;
if(1<$this->config['error_reporting'] || 2<$error_type)
{
extract($error_info);
if($msg===false) $msg = 'ob_get_contents() error';
$result = $this->messageQuit('PHP Parse Error', '', true, $type, $file, 'Snippet', $text, $line, $msg);
if ($this->isBackend())
{
$this->event->alert("An error occurred while loading. Please see the event log for more information<p>{$msg}{$snip}</p>");
}
}
}
unset ($modx->event->params);
return $msg . $snip;
}
Is there away around this? Has anyone managed to get Modx Evo working with PHP 5.4?
Continued from comments on original post...
session_is_registered() is deprecated as of PHP 5.3. You'll need to check through your snippets and find out which one is using this function, then replace it with isset($_SESSION['name_of_variable']).
Quickest way to find it would be to run a %LIKE% search in phpMyAdmin for session_is_registered on the modx_site_snippets table
Greetings,
I am writing some code inside a framework for PHP 5.3, and I am trying to catch all errors in a way that will allow me to gracefully crash on client side and add some log entry at the same time. To be sure to also catch parse errors, I am using register_shutdown_function to specifically catch parse errors.
Here is the function that I register
static function shutdown()
{
if(is_null($e = error_get_last()) === FALSE)
if($e["type"] == E_PARSE)
self::error($e["type"], $e["message"], $e["file"], $e["line"], array(self::$url));
}
The error method does two things :
It adds an error entry to a log file using fopen in append.
It execute an error display: it explicitely sets the HTTP code to 500, and display a custom format 500 error page. Some include (which I do within a wapper class, but is only an include for now) are required from there
For some reason, I can fopen my log file and append, but cannot do a simple include; it just silently dies from there.
Here is what the log outputs if I add a Log entry for each includes
static public function file($file)
{
if(class_exists("Logs"))
Logs::append("errors.log", $file . ":" . ((include $file) ? 1 : 0));
else
include $file;
}
// Inside the Logs class...
static public function append($file, $message)
{
if(!is_scalar($message))
$message = print_r($message, true);
$fh = fopen(Config::getPath("LOGS") . "/" . $file, 'a');
fwrite($fh, $message."\r\n");
fclose($fh);
}
Here what the log file gives me:
/Users/mt/Documents/workspace/core/language.php:1
...
/Users/mt/Documents/workspace/index.php:1
/Users/mt/Documents/workspace/core/view.php:1
[2010-01-31 08:16:31] Parsing Error (Code 4) ~ syntax error, unexpected T_VARIABLE {/Users/mt/Documents/workspace/controllers/controller1.php:13}
After the parse error is hitted, it does run the registered function, but as soon as it hits a new include file, it dies of a silent death... is there a way to circumvent this? Why would I be able to open a file for read/write, but not for inclusion?
Try to use Lagger
It would seem that it is related with either something in the config, either with some build specifics.
I ran the code initially on MacOSX, which would not run and fail as described, but it runs on a compiled version of PHP under Ubuntu.
Which is kinda fine for me, but pretty much makes me wonder why it still fails under OSX (XAMPP to be more precise).