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

Object of class _Request could not be converted to string #15

Closed
j-hernandez opened this issue Sep 13, 2011 · 4 comments
Closed

Object of class _Request could not be converted to string #15

j-hernandez opened this issue Sep 13, 2011 · 4 comments

Comments

@j-hernandez
Copy link

in klein.php on line 21 - according to Apache.

respond('GET', '/posts', function($request)
{
  echo "hello";
});

This code throws a 500 error.

@codingkevin
Copy link

Get this as well:

PHP Catchable fatal error: Object of class _Request could not be converted to string

That is apache error log output, same line.

Also, was getting a ton of these warnings:

PHP Notice: Undefined variable: namespace in klein.php on line 21

Is that variable suppose to be __namespace?

@j-hernandez
Copy link
Author

@codingkevin Yeah, I was able to fix that error by changing namespace to __namespace on line 21, the original error persists after that.

@samwierema
Copy link

This issue was introduced in commit 38ca436.

In commit e8357bf aliases were introduced for the respond() function (see lines 39 through 42). This means that for all GET, POST and PUT requests the $callback variable will always be converted to the $method, since those methods are callable (aliases, remember?). I've solved this issue by commenting out that part of the function, like so:

<?php
/*if (is_callable($method)) {
    $callback = $method;
    $method = null;
    $count_match = false;
} else*/if (is_callable($route)) {
    $callback = $route;
    $route = $method;
    $method = null;
}

This fixes the issue. However I can not tell whether I've broken any of the other code by doing so. It's very untested...

@chriso
Copy link
Contributor

chriso commented Sep 24, 2011

Apologies guys, should have tested this stuff before pushing it. @samwierema was right, is_callable($method) was picking up the aliases get(), post(), etc. and going down the wrong branch. It should all be fixed as of this commit.

@chriso chriso closed this as completed Sep 24, 2011
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

4 participants