Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First parameter must either be an object or the name of an existing class #181

Closed
bartrylant opened this issue Jul 23, 2019 · 5 comments
Closed

Comments

@bartrylant
Copy link

Description

I have a page with a maps field, called "location". I want to check if the location field is filled in, however, from the moment entry.location is somewhere in the template (doesn't matter where, even if it is in an if statement), I get this error:

First parameter must either be an object or the name of an existing class

Example code:

{% if entry.location.address|length %}<p><strong>Locatie</strong><br />{{ entry.location.address }}<br />
      <a href="https://www.google.com/maps/dir//{{ entry.location.address|url_encode }}/" target="_blank">Routebeschrijving</a>
      </p>{% endif %}

Additional info

  • Craft version: 3.2.5.1
  • Maps version: 3.6.1
  • PHP version: 7.2.10
  • Database driver & version: MySQL 5.7.23
@Tam
Copy link
Member

Tam commented Jul 23, 2019

@bartrylant Can you post any stacktraces related to the error (either from your web.log file or the template error screen)?

@bartrylant
Copy link
Author

yii\base\ErrorException: First parameter must either be an object or the name of an existing class in /Users/user/Sites/***-dev-4/vendor/ether/simplemap/src/models/Map.php:103
Stack trace:
#0 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/ErrorHandler.php(81): yii\base\ErrorHandler->handleError(2, 'First parameter...', '/Users/****...', 103)
#1 [internal function]: craft\web\ErrorHandler->handleError(2, 'First parameter...', '/Users/****...', 103, Array)
#2 /Users/user/Sites/***-dev-4/vendor/ether/simplemap/src/models/Map.php(103): property_exists(Array, 'address')
#3 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/helpers/Template.php(61): ether\simplemap\models\Map->canGetProperty('address')
#4 /Users/user/Sites/***-dev-4/storage/runtime/compiled_templates/83/8363166daa70da327f215ad70043ce7a64301a384acb374cf9fb64625901a2e1.php(342): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(ether\simplemap\models\Map), 'address', Array)
#5 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/Template.php(184): __TwigTemplate_e86f88ce7b539a853f17424279020d33b7040b05133abb0d66828af374fa40ad->block_content(Array, Array)
#6 /Users/user/Sites/***-dev-4/storage/runtime/compiled_templates/01/01d26c2ce348d46f7fd5a3f6f089bc809b1f1db15ebbea0919648b1cbeb5a2b4.php(93): Twig\Template->displayBlock('content', Array, Array)
#7 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/Template.php(407): __TwigTemplate_ade78ab4a9bd088ca0b6a1489ed50187b856ea886657dc159181af2232c686f3->doDisplay(Array, Array)
#8 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#9 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#10 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#11 /Users/user/Sites/***-dev-4/storage/runtime/compiled_templates/83/8363166daa70da327f215ad70043ce7a64301a384acb374cf9fb64625901a2e1.php(45): craft\web\twig\Template->display(Array, Array)
#12 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/Template.php(407): __TwigTemplate_e86f88ce7b539a853f17424279020d33b7040b05133abb0d66828af374fa40ad->doDisplay(Array, Array)
#13 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#14 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#15 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#16 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/Template.php(392): craft\web\twig\Template->display(Array)
#17 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#18 /Users/user/Sites/***-dev-4/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#19 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/View.php(343): Twig\Environment->render('wedstrijdkalend...', Array)
#20 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/View.php(393): craft\web\View->renderTemplate('wedstrijdkalend...', Array)
#21 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/Controller.php(243): craft\web\View->renderPageTemplate('wedstrijdkalend...', Array)
#22 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/controllers/TemplatesController.php(95): craft\web\Controller->renderTemplate('wedstrijdkalend...', Array)
#23 [internal function]: craft\controllers\TemplatesController->actionRender('wedstrijdkalend...', Array)
#24 /Users/user/Sites/***-dev-4/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#25 /Users/user/Sites/***-dev-4/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#26 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('render', Array)
#27 /Users/user/Sites/***-dev-4/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#28 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('templates/rende...', Array)
#29 /Users/user/Sites/***-dev-4/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#30 /Users/user/Sites/***-dev-4/vendor/craftcms/cms/src/web/Application.php(284): yii\web\Application->handleRequest(Object(craft\web\Request))
#31 /Users/user/Sites/***-dev-4/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#32 /Users/user/Sites/***-dev-4/web/index.php(21): yii\base\Application->run()
#33 {main}

@Tam Tam closed this as completed in a4457fd Jul 23, 2019
@amici-infotech
Copy link

amici-infotech commented May 5, 2022

Hey, I have the same issue with the latest version. If I change the code from this:

try
{
	if (
		property_exists($this->parts, $name) ||
		$name === 'streetAddress' ||
		in_array($name, PartsLegacy::$legacyKeys)
	) return true;
} catch (\Exception $e) {
	return false;
}

to this:

try
{

	if(is_array($this->parts)) $this->parts = (object) $this->parts;
	
	if (
		property_exists($this->parts, $name) ||
		$name === 'streetAddress' ||
		in_array($name, PartsLegacy::$legacyKeys)
	) return true;
} catch (\Exception $e) {
	return false;
}

it works. here is my trace:

{"error":"property_exists(): Argument #1 ($object_or_class) must be of type object|string, array given","exception":"TypeError","file":"/var/www/MYSITE/htdocs/vendor/ether/simplemap/src/models/Map.php","line":84,"trace":[{"file":"/var/www/MYSITE/htdocs/vendor/ether/simplemap/src/models/Map.php","line":84,"function":"property_exists"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/helpers/Template.php","line":88,"function":"canGetProperty","class":"ether\\simplemap\\models\\Map","type":"->"},{"file":"/var/www/MYSITE/htdocs/storage/runtime/compiled_templates/4a/4aa09ec8cd5b04877ff5e8e385236d22.php","line":38,"function":"attribute","class":"craft\\helpers\\Template","type":"::"},{"file":"/var/www/MYSITE/htdocs/vendor/twig/twig/src/Template.php","line":405,"function":"doDisplay","class":"__TwigTemplate_74203994ecd26b2d906897c6644efb3f","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/twig/twig/src/Template.php","line":378,"function":"displayWithErrorHandling","class":"Twig\\Template","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/twig/twig/src/Template.php","line":390,"function":"display","class":"Twig\\Template","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/twig/twig/src/TemplateWrapper.php","line":45,"function":"render","class":"Twig\\Template","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/web/View.php","line":623,"function":"render","class":"Twig\\TemplateWrapper","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/elements/Entry.php","line":1526,"function":"renderObjectTemplate","class":"craft\\web\\View","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/elements/Entry.php","line":1617,"function":"updateTitle","class":"craft\\elements\\Entry","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/services/Elements.php","line":2496,"function":"beforeSave","class":"craft\\elements\\Entry","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/services/Elements.php","line":784,"function":"_saveElementInternal","class":"craft\\services\\Elements","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/controllers/EntriesController.php","line":403,"function":"saveElement","class":"craft\\services\\Elements","type":"->"},{"function":"actionSaveEntry","class":"craft\\controllers\\EntriesController","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/yiisoft/yii2/base/InlineAction.php","line":57,"function":"call_user_func_array"},{"file":"/var/www/MYSITE/htdocs/vendor/yiisoft/yii2/base/Controller.php","line":178,"function":"runWithParams","class":"yii\\base\\InlineAction","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/yiisoft/yii2/base/Module.php","line":552,"function":"runAction","class":"yii\\base\\Controller","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/web/Application.php","line":293,"function":"runAction","class":"yii\\base\\Module","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/web/Application.php","line":602,"function":"runAction","class":"craft\\web\\Application","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/craftcms/cms/src/web/Application.php","line":272,"function":"_processActionRequest","class":"craft\\web\\Application","type":"->"},{"file":"/var/www/MYSITE/htdocs/vendor/yiisoft/yii2/base/Application.php","line":384,"function":"handleRequest","class":"craft\\web\\Application","type":"->"},{"file":"/var/www/MYSITE/htdocs/web/index.php","line":22,"function":"run","class":"yii\\base\\Application","type":"->"}]}

@AdamADigital
Copy link

AdamADigital commented May 4, 2023

I'm having the same issue. I found converting parts to an object wasn't enough, I had to make it an instance of Parts, thus:

if(is_array($this->parts)) 
                $this->parts = new Parts($this->parts);

@jamesmacwhite
Copy link

jamesmacwhite commented May 6, 2024

I'm guessing this is still present for newer PHP versions i.e. 8/8.1.

Edit: It seems to be when map field data hasn't been properly created. A process was mapping data to the map field from FeedMe, but when resaving the entry in the control panel after this, no more error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants