How to add object to smarty without error: undefined extension class 'Smarty_Internal_Method_Register_Object' - smarty3

I added Smarty 3.1.33 to my project with composer. The basic functionality works fine, but now to my I want to add an object to Smarty. For this I follow the documentation and have this code:
class My_Object {
function meth1($params, &$smarty_obj) {
return 'this is my meth1';
}
}
$myobj = new My_Object;
require_once __DIR__.'/vendor/autoload.php';
$smarty = new Smarty;
$smarty->register_object('foobar',$myobj);
Very basic according to the documentation, but the result is this:
Notice: Undefined property: Smarty_Internal_Undefined::$objMap in /home/svn/test1/trunk/smarty/vendor/smarty/smarty/libs/sysplugins/smarty_internal_extension_handler.php on line 132
Fatal error: Uncaught --> Smarty: undefined extension class 'Smarty_Internal_Method_Register_Object' <-- thrown in /home/svn/test1/trunk/smarty/vendor/smarty/smarty/libs/sysplugins/smarty_internal_undefined.php on line 62
I cannot find anything on the web about this, so am I the only one who ran into this issue? I hope someone here can help me out so I do not have to start debugging Smarty.
Thanks!

I hat a similar Problem when switching from Smarty 2.x to 3.x with the error:
Notice: Undefined property: Smarty_Internal_Undefined::$objMap in smarty\sysplugins\smarty_internal_extension_handler.php on line 132
Fatal error: Uncaught --> Smarty: undefined extension class 'Smarty_Internal_Method_Register_Resource' <-- thrown in smarty\sysplugins\smarty_internal_undefined.php on line 62
The reason was you musst change register_object to registerObject and register_resource to registerResource.
Thats all.
So in your case replace the line:
$smarty->register_object('foobar',$myobj);
with
$smarty->registerObject('foobar',$myobj);

There was one answer that you should:
The reason was you musst change register_object to registerObject and register_resource to registerResource. Thats all.
Sorry but that is not all ...
I've had the same problem and I needed to change:
register_object --> registerObject
register_resource --> registerResource
get_config_vars --> getConfigVars
config_load --> configLoad
get_template_vars --> getTemplateVars
I guess there could be more - those are the ones that I've used for my old project.

Simply include <path to Smarty>/libs/SmartyBC.class.php instead of <path to Smarty>/libs/Smarty.class.php in your project. It represents a backward compatibility wrapper class with the old function names.
See Chapter 19. SmartyBC - Backwards Compatibility Wrapper for example.

I guess you should add the invocation () parenthesis beside each constructor (i.e.
$smarty = new Smarty();
$myObj = new MyObject();

Related

JavaFX gradle depedency using Kotlin DSL but got unresolved reference for modules instead

I tried to apply JavaFX plugin to build.gradle.kts as follows
plugins {
java
id("org.openjavafx.javafxplugin") version "0.0.5"
}
javafx {
version = "12"
modules("javafx.controls", "javafx.fxml")
}
but modules() does not refer to any function it says.
the output of build said something like
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun <T : Any, C : NamedDo...
how do I resolve this?

Silverstripe 4 SapphireTest class can't be found

I've upgraded from SilverStripe 3 to 4 and now my phpUnit tests own't run because they can't find any of my Custom Classes.
There must be something missing from an autoloader or something.
I have a simple test like this
use SilverStripe\Dev\SapphireTest;
class EntityTest extends SapphireTest
{
var $Entity;
function setUp()/* The :void return type declaration that should be here would cause a BC issue */
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->Entity = new \My\API\Client\Model\Entity();
}
function testMethods(){
$this->assertMethodExist($this->Entity,'setName');
}
function assertMethodExist($class, $method) {
$oReflectionClass = new ReflectionClass($class);
assertThat("method exist", true, $oReflectionClass->hasMethod($method));
}
}
and when running I get:
$ php vendor/phpunit/phpunit/phpunit mysite/tests/EntityTest.php
Fatal error: Class 'SilverStripe\Dev\SapphireTest' not found
I ran into a similar issue with SilverStripe 4.1, here is what I found (and resolved).
1) As of 4.1, you need to use --prefer-source instead of --prefer-dist to get the test code. Test code is now omitted from the distributed packages, see https://github.com/silverstripe/silverstripe-framework/issues/7845
2) phpunit must be in require-dev at version ^ 5.7 - I had a different value and this was the cause of the autoload issue.
I've created a test module for reference, see https://github.com/gordonbanderson/travistestmodule
Cheers
Gordon
You're probably missing the test bootstrapping. SS4 still relies on the SilverStripe class manifest to register available classes (not just PSR-4 autoloaders), so you need to include it. Try either of these:
$ vendor/bin/phpunit --bootstrap vendor/silverstripe/framework/tests/bootstrap.php mysite/tests
or create a phpunit.xml file in your root project:
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
</phpunit>
You may also use the equivalent file from the CMS module instead, but you probably won't see any differences until you start to integrate your testsuite into a CI provider.

Error 500 Call to undefined function thrive_get_theme_options() when trying to get to customize in WP

My site uninstalled all plugins so I reactivated and since then I have been greeted by Error 500 everytime I try to get to Customise (WP).
I checked out error_log and it's pointing to the funtions.php line 659 (starts 3rd line down):
function thrive_exclude_category($query)
{
$hide_cat_option = thrive_get_theme_options('hide_cats_from_blog');
if (!is_string($hide_cat_option)) {
$hide_cat_option = "";
}
$hide_categories = is_array(json_decode($hide_cat_option)) ? json_decode($hide_cat_option) : array();
$temp_query_string_part = "";
foreach ($hide_categories as $temp_cat_id) {
$temp_query_string_part .= "-" . $temp_cat_id . " ";
}
This is probably simple stuff, however, I suck. I have been lumbered with maintaining the sites and really have no say in the matter. Thanks in advance
In one of the projects I found this problem too. After study logs and debug project I find this function don't know about another function which used in theme PHP message: PHP Fatal error: Uncaught Error: Call to undefined function thrive_get_theme_options(). The main problem here in filter which running before all files will be included in theme. So function thrive_exclude_category don't find where declared thrive_get_theme_options because pre_get_posts running before we included files:
add_filter('pre_get_posts', 'thrive_exclude_category')
We need run this filter after use after_setup_theme
function run_func(){
add_filter('pre_get_posts', 'thrive_exclude_category', 999);
}
add_action('after_setup_theme', 'run_func`);
After this you not get any error and you can use your filter.
Try reactivate all plugins required by Thrive theme because of Fatal: Call to undefined function thrive_get_theme_options()

How to get orders array in magento 2 in custom module?

I need orders array in custom module controller. how to get that?
tried this, but didn't work:
$orderCollection = Mage::getModel('sales/order')->getCollection(); echo "";
print_r($orderCollection);
Error:
"Fatal error: Class 'WebHive\SPS\Controller\Index\Mage' not found in C:\wamp\www\magento_test\app\code\WebHive\SPS\Controller\Index\Index.php on line 76"
All suggestions would be appreciated....
May be following could be helpful for you.
Try this code in your controller function
require_once 'app/Mage.php';
Mage::app();
$orderCollection = Mage::getModel('sales/order')->getCollection();

How do I set up FirePHP version 1.0?

I love FirePHP and I've been using it for a while, but they've put out this massive upgrade and I'm completely flummoxed trying to get it to work. I think I'm copying the "Quick Start" code (kind of guessing at whatever changes are necessary for my server configuration), but for some reason, FirePHP's "primary" function, FirePHP::to() isn't doing anything. Can anyone please help me figure out what I'm doing wrong? Thanks.
<?php
define('INSIGHT_IPS', '*');
define('INSIGHT_AUTHKEYS', '290AA9215205F24E5104F48D61B60FFC');
define('INSIGHT_PATHS', __DIR__);
define('INSIGHT_SERVER_PATH', '/doc_root/hello_firephp2.php');
set_include_path(get_include_path . ":/home8/jayharri/php/FirePHP/lib"); // path to FirePHP library
require_once('FirePHP/Init.php');
$inpector = FirePHP::to('page');
var_dump($inspector);
$console = $inspector->console();
$console->log('hello firephp');
?>
Output:
NULL
Fatal error: Call to a member function console() on a non-object in /home8/jayharri/public_html/if/doc_root/hello_firephp2.php on line 14
The inspector variable is spelled wrong where you are assigning it and you are missing a bracket when getting the include path.
Try the following:
define('INSIGHT_IPS', '*');
define('INSIGHT_AUTHKEYS', '290AA9215205F24E5104F48D61B60FFC');
define('INSIGHT_PATHS', __DIR__);
define('INSIGHT_SERVER_PATH', '/doc_root/hello_firephp2.php');
set_include_path(get_include_path() . ":/home8/jayharri/php/FirePHP/lib");
require_once('FirePHP/Init.php');
$inspector = FirePHP::to('page');
$console = $inspector->console();
$console->log('hello firephp');
Also, according to the INSIGHT_SERVER_PATH constant make sure you have a script with FirePHP installed at:
http:://<hostname>/doc_root/hello_firephp2.php

Resources