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

[2.4] Call to a member function getChildren() on a non-object #25

Open
nathanhornby opened this issue Jun 26, 2014 · 45 comments
Open

[2.4] Call to a member function getChildren() on a non-object #25

nathanhornby opened this issue Jun 26, 2014 · 45 comments

Comments

@nathanhornby
Copy link

When attempting to login with a user account assigned a custom role I'm getting the following error:

Call to a member function getChildren() on a non-object    
An error occurred in [redacted]/extensions/author_roles/extension.driver.php around line 459

I won't pretend to understand the issue, as after a quick check the item in question is, in fact, an object.

This is on Symphony 2.4.

@nathanhornby
Copy link
Author

I'm going to summon a few Symphonists, sorry in advance! (@designermonkey @brendo @nitriques @michael-e @nilshoerrmann) - as I really need to use this extension and it seems completely unmaintained - not sure how likely it is for anyone else to see my cries for help.

I've made some fixes that enable 2.5 compatibility (Author-> to Author()->), but this bug (from 2.4) still hasn't been resolved and I can't work it out.

It all looks fine to me, the error is insistent that it's not an object, but it is. I've tried getting around this in quite a few ways but it always boils back down to this. Oddly I can output the result of $element->getChildren() just fine, it only seems to be an issue when referencing it. I have a feeling a more seasoned PHP person will resolve this quite easily!

If you can quickly point me in the right direction I'm happy to put the PR together. Assuming it's not a bigger job than it seems.

@designermonkey
Copy link
Contributor

If you can show me the stack trace from the error, I can look at it. That function gets passed an element, and I need to see where that element comes from :)

@nathanhornby
Copy link
Author

@designermonkey How do I instigate a stack trace myself?

@designermonkey
Copy link
Contributor

It should be listed under the error you've shown?

@nathanhornby
Copy link
Author

Ah I see, nope, not in this case :( I just get exactly what's quoted in the original issue.

@designermonkey
Copy link
Contributor

Any page you're on in particular? Or just the login page?

@nathanhornby
Copy link
Author

The error is shown after login, so when trying to display a page, i.e. the default section for the user.

The section is one they're allowed to view as well, so it's not that.

@nilshoerrmann
Copy link

Do you have Order Entries installed? I had a similar problem on the login page once.

@designermonkey
Copy link
Contributor

Also, try dropping debug_print_backtrace() just inside that function, and log in again.

@nathanhornby
Copy link
Author

Do you have Order Entries installed?

I certainly do. Although it'd be pretty hard to test as removing it would involve quite a bit of section editing.

@nathanhornby
Copy link
Author

@designermonkey
I dropped:

var_dump(debug_print_backtrace());
exit;

Just inside the findChildren function and get a rather big output - is that what you wanted, anything in particular you needed to see? It's a rather lengthy and difficult to parse output.

@nilshoerrmann
Copy link

Try uncommenting the delegate functions in the extension driver.

Am 21.08.2014 um 11:57 schrieb Nathan Hornby notifications@github.com:

I certainly do. Although it'd be pretty hard to test as removing it would involve quite a bit of section editing.


Reply to this email directly or view it on GitHub.

@nathanhornby
Copy link
Author

@nilshoerrmann

Sorry I can't see any functions currently commented out - am I misunderstanding your instruction?

@nilshoerrmann
Copy link

Sorry, I meant the other way around: try to comment out the functions referenced by the delegates.

@nathanhornby
Copy link
Author

Ah, I get a different error (with a stack trace!) if I set the default area to somewhere where there isn't an Order Entries field:

Symphony Warning: strpos() expects parameter 1 to be string, object given

foreach($children as $key => $child) {
                         if(strpos($child->getValue(),__('Create New')) !== false) {
                             $value = $child->getValue();
                             $child->setValue('<span>'.strip_tags(str_replace(__('Create New'), '', $value)).'</span><span class="create" />');
                         }
                     }
[:0]
    GenericErrorHandler::handler();
[xxx/extensions/author_roles/extension.driver.php:259]
    strpos();
[xxx/extensions/author_roles/extension.driver.php:212]
    extension_author_roles->adjustIndex();
[xxx/symphony/lib/toolkit/class.extensionmanager.php:709]
    extension_author_roles->checkCallback();
xxx/symphony/lib/core/class.administration.php:459]
    ExtensionManager::notifyMembers();
[xxx/symphony/lib/boot/func.utilities.php:236]
    Administration->display();
[xxx/symphony/lib/boot/func.utilities.php:207]
    symphony_launcher();
[xxx/index.php:14]
    symphony();

@nilshoerrmann I tried that just in case (on the Order Entires and this extension) and it didn't seem to have an impact.

@designermonkey
Copy link
Contributor

well, just pastie it and attach the link here, and I'll look a little later. Off out for lunch.

@nathanhornby
Copy link
Author

@designermonkey It's bigger than the 64kb limit on Pastie :p

It's a massive wall of stuff - unless you're looking for something in particular within it, I'm not sure the raw dump will be much help?

@nathanhornby
Copy link
Author

@nitriques
Copy link

@nathanhornby From what I see, you are dealing with a major case of recursion shit.

Can you try:

  1. changing the function signature (line 452) to this (adding the XMLElement type hint)
private static function findChildren(XMLElement $element, $names) {

and report back the new error.

  1. add this code below line 457
if ($element == null) { return $children }

The recursion loops looks weird to me as it does not have any exit checks.

@nitriques
Copy link

the second snippet is missing a ; (can't edit my posts, I am on a really old macbook stuck with Chrome 21)

@nathanhornby
Copy link
Author

Thanks! I'll give this a try when I get the chance and report back.

On 22 Aug 2014, at 02:30, Nicolas Brassard notifications@github.com wrote:

@nathanhornby From what I see, you are dealing with a major case of recursion shit.

Can you try:

  1. changing the function signature (line 452) to this (adding the XMLElement type hint)

private static function findChildren(XMLElement $element, $names) {
and report back the new error.

  1. add this code below line 457

if ($element == null) { return $children }
The recursion loops looks weird to me as it does not have any exit checks.


Reply to this email directly or view it on GitHub.

@nathanhornby
Copy link
Author

@nitriques I've added that in (all makes sense), however unfortunately it hasn't had any effect.

Symphony Warning: strpos() expects parameter 1 to be string, object given

For line 259. So same as the error above (non order-entries one, order entries is not installed on the site im testing this on).

@nitriques
Copy link

Did you revert all other changes you made ? We should at least go further in the stack...
Or can you still reproduce the original Call to a member function getChildren() on a non-object thing?

@nathanhornby
Copy link
Author

Ah I see, well that was due to the presence of Order Entries post-login.

As noted I don't have order entries on this build. However I've just set a section up with it and hitting that section post-login with the author role is now giving me:

Symphony Recoverable Error: Argument 1 passed to extension_author_roles::findChildren() must be an instance of XMLElement, string given, called in [redacted]/extensions/author_roles/extension.driver.php on line 461 and defined

Highlighting line 452.

Important bit of the backtrace:

extension_author_roles::findChildren();
extension_author_roles->adjustIndex();
extension_author_roles->checkCallback();
ExtensionManager::notifyMembers();

@nitriques
Copy link

Great we are making progress. Thr non object is that string. Can you post the complete stack trace please ?

Nicolas Brassard

Envoyé de mon iPhone: désolé si la qualité de mon français fait défaut.

On Aug 22, 2014, at 17:27, Nathan Hornby notifications@github.com wrote:

Ah I see, well that was due to the presence of Order Entries post-login.

As noted I don't have order entries on this build. However I've just set a section up with it and hitting that section post-login with the author role is now giving me:

Symphony Recoverable Error: Argument 1 passed to extension_author_roles::findChildren() must be an instance of XMLElement, string given, called in [redacted]/extensions/author_roles/extension.driver.php on line 461 and defined

Highlighting line 452.


Reply to this email directly or view it on GitHub.

@nathanhornby
Copy link
Author

You probably missed my edit, but here's the full backtrace anyway!

[[redacted]/extensions/author_roles/extension.driver.php:452]
GenericErrorHandler::handler();
[[redacted]/extensions/author_roles/extension.driver.php:461]
extension_author_roles::findChildren();
[[redacted]/extensions/author_roles/extension.driver.php:461]
extension_author_roles::findChildren();
[[redacted]/extensions/author_roles/extension.driver.php:461]
extension_author_roles::findChildren();
[[redacted]/extensions/author_roles/extension.driver.php:461]
extension_author_roles::findChildren();
[[redacted]/extensions/author_roles/extension.driver.php:367]
extension_author_roles::findChildren();
[[redacted]/extensions/author_roles/extension.driver.php:212]
extension_author_roles->adjustIndex();
[[redacted]/symphony/lib/toolkit/class.extensionmanager.php:709]
extension_author_roles->checkCallback();
[[redacted]/symphony/lib/core/class.administration.php:459]
ExtensionManager::notifyMembers();
[[redacted]/symphony/lib/boot/func.utilities.php:236]
Administration->display();
[[redacted]/symphony/lib/boot/func.utilities.php:207]
symphony_launcher();
[[redacted]/index.php:14]
symphony();

@nitriques
Copy link

I do not know why a string would get stored as a "child" (@brendo, @designermonkey ?) but seems like that's what you have on your setup... Would you mind to try this implementation ?

    private static function findChildren($element, $names) {
        if(!is_array($names)) {
            $names = explode(',', $names);
        }

        $children = array();

        if (!($element instanceof XMLElement)) {
            return $children;
        }

        foreach($element->getChildren() as $child) {
            $children = array_merge($children, self::findChildren($child,$names));

            if(in_array($child->getName(), $names )) {
                $children[] = $child;
            }
        }

        return $children;
    }

@nathanhornby
Copy link
Author

@nitriques

Line 466 is throwing the error:

Symphony Fatal Error: Call to a member function getName() on a non-object

Content of line 466:

if(in_array($child->getName(), $names )) {

@nathanhornby
Copy link
Author

Ah, interestingly the $child object is dumping as a variable:

string(7) "Actions"

@brendo
Copy link

brendo commented Aug 26, 2014

I've forked this to Symphonists, and created an integration branch which incorporates your pull request and a couple of additional fixes.

This is by no means exhaustive, and to be honest, it's a very involved task to get this extension up to date. It's done an admirable job of using the awful XMLElement class and as that has evolved (better and worse), the modifications this extension requires must be carefully tested to ensure it's correct.

I've never used Author Roles for any project, so I'm far from an expert in this regard and will not be able to complete the update.

@nathanhornby
Copy link
Author

Thanks Brendan.

So would you say it could do with a rewrite?

It's a very handy extension when you need it - Ive used it a couple of times for enabling user access to a 'blogging' area whilst keeping them away from the site data. It's a pretty elegant and powerful extension so it'd be a shame to see it get left behind.

On 26 Aug 2014, at 13:26, Brendan Abbott notifications@github.com wrote:

I've forked this to Symphonists, and created an integration branch which incorporates your pull request and a couple of additional fixes.

This is by no means exhaustive, and to be honest, it's a very involved task to get this extension up to date. It's done an admirable job of using the awful XMLElement class and as that has evolved (better and worse), the modifications this extension requires must be carefully tested to ensure it's correct.

I've never used Author Roles for any project, so I'm far from an expert in this regard and will not be able to complete the update.


Reply to this email directly or view it on GitHub.

@designermonkey
Copy link
Contributor

There are new delegates available in the Author perspective in Symphony.
I had these added to allow us to revisit this concept, as currently, it
only pseudo-hides sections and nav items (last I was aware).

I have a concept to flesh out from a planning perspective, but
definitely no time to actually develop anything :(

Nathan Hornby wrote:

Thanks Brendan.

So would you say it could do with a rewrite?

It's a very handy extension when you need it - Ive used it a couple of
times for enabling user access to a 'blogging' area whilst keeping
them away from the site data. It's a pretty elegant and powerful
extension so it'd be a shame to see it get left behind.

On 26 Aug 2014, at 13:26, Brendan Abbott notifications@github.com
wrote:

I've forked this to Symphonists, and created an integration branch
which incorporates your pull request and a couple of additional fixes.

This is by no means exhaustive, and to be honest, it's a very
involved task to get this extension up to date. It's done an admirable
job of using the awful XMLElement class and as that has evolved
(better and worse), the modifications this extension requires must be
carefully tested to ensure it's correct.

I've never used Author Roles for any project, so I'm far from an
expert in this regard and will not be able to complete the update.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#25 (comment).

@nitriques
Copy link

@nathanhornby @brendo

The code should then be

    private static function findChildren($element, $names) {
        if(!is_array($names)) {
            $names = explode(',', $names);
        }

        $children = array();

        if (!($element instanceof XMLElement)) {
            return $children;
        }

        foreach($element->getChildren() as $child) {
            $children = array_merge($children, self::findChildren($child,$names));

            if($child instanceof XMLElement && in_array($child->getName(), $names )) {
                $children[] = $child;
            }
        }

        return $children;
    }

I've never used it either BTW.

@nathanhornby
Copy link
Author

You cracked it @nitriques good job!

Especially as you don't even use it :)

@designermonkey

it only pseudo-hides sections and nav items (last I was aware).

Depends what you mean by 'pseudo-hides' it, but it's not still in the DOM, if that's what you mean (we are still talking about this extension?).

I have a concept to flesh out from a planning perspective

but definitely no time to actually develop anything :(

Happy/Sad

@nitriques
Copy link

You cracked it @nitriques good job!

My pleasure, I really like recursions: they are so easy to code and so evil!

@designermonkey
Copy link
Contributor

Depends what you mean by 'pseudo-hides' it

Removes it from the DOM, but if you know the URL... You can still see the page. But, I haven't checked this for a long time.

@nathanhornby
Copy link
Author

Removes it from the DOM, but if you know the URL...

Ah, you may be right there, haven't tested that. In my implementations that isn't really an issue, but if it's for more sensitive use-cases that's an important point (if the case, I'll test at some point).

@nitriques I can get your fix added into a commit in the new Symphonists fork (I'm assuming this will become the new maintained version?) - or did you want to get it added in yourself? I won't have a chance to do it until tomorrow either way.

@nitriques
Copy link

@nathanhornby please do it I do not even use this extension!

As for the symphonist fork, I'll let @brendo answer.

nathanhornby added a commit to nathanhornby/author_roles that referenced this issue Aug 26, 2014
@nathanhornby
Copy link
Author

@designermonkey Just wanted to confirm that you're correct - although the extension removes the menu items it doesn't actively prevent the user from navigation to a section via the URL.

I'm assuming this isn't a particularly tall order though? Does Symphony provide a way to easily trigger the 'Access Denied' message like you see when an 'Author' attempts to visit the preferences page? There'll be a delegate we can tie this to, I assume, along with an existing piece of logic already used to hide the sections.

@brendo
Copy link

brendo commented Aug 27, 2014

            Administration::instance()->throwCustomError(
                __('You are not authorised to access this page.'),
                __('Access Denied'),
                Page::HTTP_STATUS_UNAUTHORIZED
            );

@nathanhornby
Copy link
Author

Thanks @brendo ! I'll take a look at this myself later, see if I can't cobble something together.

@andrewminton
Copy link

Has this extension been firmed up for use with 2.5 and 2.6? looking at the above it seems a fork over to Symphonists has the changes but I get getName() errors still.

@nitriques
Copy link

@andrewminton I do not used it for a while. Please send any PR to the symphonist repo tho. Thanks.

@andrewminton
Copy link

Seems like a checkfor an object or not fixes it here too... needs more testing but will send PR to repo 'Symphonists' when done.

@nitriques
Copy link

Thanks Andrew.

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

6 participants