Skip to content

Conversation

jomiojeda
Copy link

…making translation return always default culture translation. It should be true.

…ng translation returning always default culture
Copy link
Contributor

@j0k3r j0k3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to add a test to generate the error?

@jomiojeda
Copy link
Author

I will try to when I have some time. For now the fix solved the problem for our client. Thanks.

@alquerci
Copy link
Contributor

alquerci commented Jul 21, 2018

It is not a PHP-7 bug but just a modification of the deep isset behaviour.

Deep isset() on class that implement ArrayAccess

<?php

isset($arrayAccess['foo']['bar']);

Before PHP-7.0

<?php

$arrayAccess->offsetGet('foo')->offsetExists('bar');

PHP-7.0 and after

<?php

if ($arrayAccess->offsetExists('foo')) {
    $arrayAccess->offsetGet('foo')->offsetExists('bar');
}

Solution

Just need to do the following modification.

<?php

// The relationship must be fetched in order to check the culture existance.
// Related to PHP-7.0 compatibility so an explicit call to method get is required.
$translation = $record['Translation'];

// process the translation.

PS: There is the same behaviour for deep isset() on class that define __isset() and __get().

Copy link

@dr0bz dr0bz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works!

What is missing now to get it into master?

P.S.: here some more info on the isset & ArrayAccess php bug: https://bugs.php.net/bug.php?id=69659

{
$culture = sfDoctrineRecord::getDefaultCulture();
if (isset($record['Translation'][$culture]) && '' != $record['Translation'][$culture][$name])
if (is_subclass_of($record['Translation'][$culture], 'Doctrine_Record') && '' != $record['Translation'][$culture][$name])
Copy link
Contributor

@alquerci alquerci Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point of view.

We need to take gloves, as the test suite does not cover this part of the code.

Using is_subclass_of() is too much.
Indeed, it works.

This change forces the call on $record->get('Translation').
Which was not done on PHP 7+ but done on PHP 5, with the isset().
To dig deeper, read #184 (comment)


Also, the same bug has been fixed on doctine1 where there is a proof that works as it should.

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.

4 participants