PHPBB_ENVIRONMENT, production vs development

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Blitze
Registered User
Posts: 366
Joined: Tue Nov 29, 2005 5:06 pm

PHPBB_ENVIRONMENT, production vs development

Post by Blitze » Tue May 08, 2018 3:00 am

I'm experiencing some weirdness in the development vs production environment that has got me scratching my head for hours. As of php 5.3, you can use the ternary operator shorthand like this:

Code: Select all

$foo = array();
echo $foo['key'] ?: "default";   // prints 'default'
echo $bar ?: 3;  // prints 3
This works when the phpbb environment is 'production' but when it is 'development', it returns "undefined index 'key'" and "undefined variable $bar" respectively.

I'm I missing something? Please help.
My Extensions: phpBB SiteMaker

Blitze
Registered User
Posts: 366
Joined: Tue Nov 29, 2005 5:06 pm

Re: PHPBB_ENVIRONMENT, production vs development

Post by Blitze » Tue May 08, 2018 3:29 am

Similarly, using array language keys in twig work in production but not in development. For example,

Code: Select all

{{ lang(['datetime', 'Sunday'], 1) }}
works in production but fails in development with error "array to string conversion". I think of this one as a bug as it can be corrected with a condition in phpBB/phpbb/template/twig/extension.php:

https://github.com/phpbb/phpbb/blob/929 ... n.php#L175
My Extensions: phpBB SiteMaker

User avatar
3Di
Registered User
Posts: 12983
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: PHPBB_ENVIRONMENT, production vs development

Post by 3Di » Tue May 08, 2018 4:34 am

How did you set your phpbb_environment?
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Blitze
Registered User
Posts: 366
Joined: Tue Nov 29, 2005 5:06 pm

Re: PHPBB_ENVIRONMENT, production vs development

Post by Blitze » Tue May 08, 2018 4:36 am

in phpBB/config.php

Code: Select all

@define('PHPBB_ENVIRONMENT', 'development');
My Extensions: phpBB SiteMaker

User avatar
3Di
Registered User
Posts: 12983
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: PHPBB_ENVIRONMENT, production vs development

Post by 3Di » Tue May 08, 2018 4:39 am

That's not enough AFAIR, you need to copy also the config/development folder from the phpBB repository

https://github.com/phpbb/phpbb/tree/master/phpBB/config

I don't remember if there is something else to do ATM, I did that long time ago.
Pls try and report.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Blitze
Registered User
Posts: 366
Joined: Tue Nov 29, 2005 5:06 pm

Re: PHPBB_ENVIRONMENT, production vs development

Post by Blitze » Tue May 08, 2018 4:44 am

Sorry, I should have given you more info. I am using a cloned copy of the 3.2.x branch. So it does have the phpBB/config/development folder.
My Extensions: phpBB SiteMaker

Blitze
Registered User
Posts: 366
Joined: Tue Nov 29, 2005 5:06 pm

Re: PHPBB_ENVIRONMENT, production vs development

Post by Blitze » Tue May 08, 2018 5:07 am

BTW I'm running PHP 7.0.21-1~ubuntu14.04.1+deb.sury.org+1 (cli).

Does this also mean that when we run extension tests using travis it is being run in production rather development? Can this be changed somehow?
My Extensions: phpBB SiteMaker

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3292
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: PHPBB_ENVIRONMENT, production vs development

Post by kasimi » Tue May 08, 2018 5:40 am

Your code doesn't behave differently, the problems are just ignored when in production. If your environment is set to development, all errors are reported.

https://github.com/phpbb/phpbb/blob/rel ... n.php#L101
https://github.com/phpbb/phpbb/blob/rel ... ug.php#L55

The Elvis operator ?: doesn't do isset() for you, $a ?: $b is merely a short version of $a ? $a : $b.

The lang() issue seems to be an unsupported feature, or bug if you prefer. :P

Blitze
Registered User
Posts: 366
Joined: Tue Nov 29, 2005 5:06 pm

Re: PHPBB_ENVIRONMENT, production vs development

Post by Blitze » Tue May 08, 2018 4:17 pm

Thanks kasimi, I knew there was the possibility that I did not correctly understand what the shorthand was supposed to do. I was thinking it worked with undefined variables but it doesn't seem to. So

Code: Select all

echo $some_undefined_var ?: 2;
will not work but

Code: Select all

$foo = false;
echo $foo ?: 2;
does. What was confusing me is that in production, it wasn't just being ignored. It returning the expected result.

Same with the lang() issue. It is not just being ignored in production. It actually works and returns the expected translation but fails in development. I can open a bug and provide a PR to fix it.

As for Travis, is it possible to make it run in development so bugs like this are not simply ignored?

Thanks
My Extensions: phpBB SiteMaker

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3292
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: PHPBB_ENVIRONMENT, production vs development

Post by kasimi » Wed May 09, 2018 8:43 am

Blitze wrote:
Tue May 08, 2018 4:17 pm
I can open a bug and provide a PR to fix it.
Please do.
Blitze wrote:
Tue May 08, 2018 4:17 pm
As for Travis, is it possible to make it run in development so bugs like this are not simply ignored?
I'm sure there's a more elegant way, but you could try calling error_reporting(-1); in setUpBeforeClass().

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4680
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: PHPBB_ENVIRONMENT, production vs development

Post by VSE » Sat May 12, 2018 1:23 am

a missing array key will trigger a php warning or notice, but not an error. The development will display php warning/notices, whereas production will not (only errors).

That's why you see the message in development but not production.

As for the rest, listen to kasimi.
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

Blitze
Registered User
Posts: 366
Joined: Tue Nov 29, 2005 5:06 pm

Re: PHPBB_ENVIRONMENT, production vs development

Post by Blitze » Tue May 15, 2018 3:55 am

So I was hesitant to create a bug on this as it is only discoverable when in development mode but I finally created one here: https://tracker.phpbb.com/browse/PHPBB3-15666.

I am ready to submit a pull request to fix it but here is a question: Do I need to provide tests? It feels like it would be a useless test (as it would never fail) because it appears PHP errors are also ignored when running tests.

I made a change to the test bootstrap to display errors and so the test would error out without this fix. But this resulted in over a thousand errors and 3 failures for the existing phpBB tests.

Shouldn't debug mode be turned on when running tests? Should I provide a test if it is practically useless?
My Extensions: phpBB SiteMaker

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: Toxyy and 13 guests