Skip to content

[2.1] sub-requests are now created with the same class as their parent #7381

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

Merged
merged 1 commit into from
Mar 15, 2013

Conversation

jfsimon
Copy link
Contributor

@jfsimon jfsimon commented Mar 14, 2013

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #7185

@lsmith77
Copy link
Contributor

oh .. i thought this was already the case!

@gnutix
Copy link
Contributor

gnutix commented Mar 15, 2013

Thanks for the PR @jfsimon ! I just override the Request class for a custom getClientIp() method and I sure will need your fix in order for it to work in all scenarios. I'll test your patch in my project as soon as possible.

fabpot added a commit that referenced this pull request Mar 15, 2013
This PR was merged into the 2.1 branch.

Commits
-------

e51432a sub-requests are now created with the same class as their parent

Discussion
----------

[2.1] sub-requests are now created with the same class as their parent

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7185

---------------------------------------------------------------------------

by lsmith77 at 2013-03-14T19:54:13Z

oh .. i thought this was already the case!

---------------------------------------------------------------------------

by gnutix at 2013-03-15T09:57:55Z

Thanks for the PR @jfsimon ! I just override the Request class for a custom getClientIp() method and I sure will need your fix in order for it to work in all scenarios. I'll test your patch in my project as soon as possible.
@fabpot fabpot merged commit e51432a into symfony:2.1 Mar 15, 2013
@gnutix
Copy link
Contributor

gnutix commented Mar 15, 2013

@fabpot Thanks for the awesomely quick merge! :D

@henrikbjorn
Copy link
Contributor

Wouldnt it be simpler to do

<?php
$subRequest = $request::create();

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 15, 2013

@henrikbjorn I didn't knew it was possible... it looks weird (but simpler yep).

@gnutix
Copy link
Contributor

gnutix commented Mar 15, 2013

@jfsimon It's new to PHP 5.3. I too find the syntax a bit disturbing (as it kind of mix up static and non-static calls syntax).

@henrikbjorn
Copy link
Contributor

@gnutix mix up ? It is clear that it is a static call :) and in any case you can call static methods as nonstatic so $subRequest = $request->create() would also be possible.

@jfsimon
Copy link
Contributor Author

jfsimon commented Mar 15, 2013

@gnutix are you a bass player? cause I'm too ;)

@gnutix
Copy link
Contributor

gnutix commented Mar 15, 2013

@henrikbjorn Visually, I'm not used to see static calls starting with "$" ("instance = not static" in my mind :P). But it's just a matter of habits. :)
@jfsimon I try to be! Kind of missing my old band actually...

@henrikbjorn
Copy link
Contributor

php > class Original { public static function create() { return new static(); } }
php > class Inherited extends Original { }
php > $original = new Original;
php > $inherited = new Inherited();
php > var_dump($original::create());
object(Original)#3 (0) {
}
php > var_dump($inherited::create());
object(Inherited)#2 (0) {
}

Works fine :)

@gnutix
Copy link
Contributor

gnutix commented Mar 15, 2013

@henrikbjorn I've tried too, but it's a syntax ($instance::staticMethod();) that's not described in the PHP documentation apparently : http://php.net/manual/fr/language.oop5.static.php (or I'm missing it).

@asm89
Copy link
Contributor

asm89 commented Mar 15, 2013

@gnutix Example #2 on that page? :)

@gnutix
Copy link
Contributor

gnutix commented Mar 15, 2013

@asm89 In the second example, $classname is a string ('Foo'), not an instance of the Foo class. :P There should be an example 3 as follow :

<?php
class Foo
{
    public static function aStaticMethod() {
        // ...
    }
}

$class = new Foo;
$class::aStaticMethod(); // Since PHP 5.3.0
?>

However, it's probably not the right place to discuss it ! :)

fabpot added a commit that referenced this pull request Mar 15, 2013
This PR was merged into the 2.1 branch.

Commits
-------

b9c37f2 changed sub-requests creation to '::create()'

Discussion
----------

changed sub-requests creation to '::create()'

Added @henrikbjorn suggestion to #7381
fabpot added a commit that referenced this pull request Mar 18, 2013
This PR was merged into the 2.2 branch.

Commits
-------

53cf12b replaced new occurences of 'Request::create()' with '::create()'

Discussion
----------

[2.2] sub-requests are now created with the same class as their parent

Following #7381

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7185, #7186
fabpot added a commit that referenced this pull request Oct 1, 2013
…ss (fabpot)

This PR was merged into the master branch.

Discussion
----------

[HttpFoundation] added a way to override the Request class

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7461, #7453
| License       | MIT
| Doc PR        | symfony/symfony-docs#3021

This is an alternative implementation for #7461.

I've also reverted #7381 and #7390 as these changes are not needed anymore.

Todo:

 - [ ] add some tests

Commits
-------

464439d [HttpFoundation] added a way to override the Request class
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

Successfully merging this pull request may close these issues.

6 participants