Toujours la même chose :
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/notification/type/post.php on line 382: Undefined array key "forum_name"
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 1821: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3076)
How to fix it ?
Thinking...
...done thinking.
## TL;DR
The “Undefined array key **forum_name**” warning is the root cause.
It is thrown while the **post notification** class builds the data that
will be sent to users. Because the key isn’t set, PHP emits a warning,
which in turn starts output **before** PHP can send HTTP headers → the
“Cannot modify header information” warning.
Fix the missing **forum_name** entry (or the code that should set it) and
the header‑sent error disappears automatically.
---
##
What the stack‑trace is telling you
| File / Line | Message | Why it matters |
|-------------|---------|----------------|
| `phpbb/notification/type/post.php:382` | **Undefined array key
“forum_name”** | The notification class expects `$data['forum_name']` (or
`$event['forum_name']`) to exist when it builds the email/alert. |
| `includes/functions.php:1821` | **Cannot modify header information** |
PHP has already sent some output (the warning above). When phpBB later
tries to send a redirect or a cookie header it fails. This is a *symptom*,
not the *root* cause. |
All other “output started at … functions.php:3076” comes from the same
warning that was printed earlier.
---
##
Why `forum_name` can be missing
| Situation | How it happens |
|-----------|-----------------|
| **Out‑of‑date core files** (e.g. you upgraded from 3.2 → 3.3 but only
some files were replaced) | Newer notification code now expects a
`forum_name` entry that older PHP files never supplied. |
| **Broken/disabled language pack** | The language file that defines
`$user->lang['FORUM']` or the template variable used to fill
`$data['forum_name']` is missing, causing the variable to be empty/unset.
|
| **Custom extension overriding the post notification** | An extension
may hook into `notification_manager` and alter the `$event` array,
accidentally dropping `forum_name`. |
| **Database inconsistency** (e.g. forum rows missing the `forum_name`
column) | Very rare, but if the `phpbb_forums` table was manually edited
and the column was renamed/dropped, the query that fetches the name fails.
|
| **PHP version incompatibility** (PHP 8.1+ strictness) | Prior to PHP 8.0
accessing a non‑existent key silently returned `null`. PHP 8.1 throws a
*warning* that now shows up in the debug log. |
---
##
Quick “sanity‑check” checklist
1. **Clear the cache** – `ADM` → **General → Purge the cache** (or delete
everything in `cache/` except `/.htaccess` and `config.php`).
*Why?* Some stale PHP files can linger after an upgrade.
2. **Confirm core version** – go to *Admin Control Panel → General →
Server configuration → Version check* (or look at
`includes/constants.php`).
*If you are on a version older than the latest 3.3.x stable, run the
**official upgrade** script.*
3. **Verify language pack** – in the ACP, *System → Language packs* → make
sure the pack you use (e.g. “English (United Kingdom)”) is **installed**
and **enabled**. Re‑install it if needed.
4. **Disable custom extensions** temporarily.
Rename the extension folder (`ext/yourvendor/yourext/`) to something
like `ext/yourvendor/yourext.disabled`.
If the warning disappears → the extension is the culprit.
5. **Check the database** – run the following query (via phpMyAdmin,
Adminer, or MySQL client) to assure the column exists:
```sql
SHOW COLUMNS FROM phpbb_forums LIKE 'forum_name';
```
It should return a row (`forum_name` varchar(255) NOT NULL). If it’s
missing, you have a corrupted install; re‑import the core schema from the
current phpBB release.
---
##
Fixing the root cause
Below are three practical ways to get rid of the missing `forum_name`
entry, ordered from **least invasive** to **most invasive**.
### 4.1 Core‑only fix (recommended)
Open `phpbb/notification/type/post.php` around line 380‑390 (your line
numbers may differ slightly). You’ll see something like:
```php
$forum_name = $this->get_data('forum_name'); // <-- line 382 (example)
```
Replace the block with a defensive fallback:
```php
$forum_name = $this->get_data('forum_name');
// If the data is missing (old PHP < 8.0 behavior) we fetch it manually.
if (empty($forum_name))
{
// $this->get_data('forum_id') is set by the notification builder.
$forum_id = $this->get_data('forum_id');
$sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . " WHERE forum_id =
$forum_id";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$forum_name = $row['forum_name'] ?? '[unknown]';
}
```
**Why this works:** The code now **guarantees** that `$forum_name` is
always defined, regardless of whether the upstream notification builder
supplied it. The fallback fetches it directly from the DB, which is safe
and cheap (single row).
> **Caution** – If you later upgrade phpBB, this manual edit may be
overwritten. Record the change in a separate “patch” file, or create a
tiny *extension* that overrides the notification class (see
“Extension‑level fix” below).
---
### 4.2 Extension‑level fix (cleaner, upgrade‑safe)
Create a tiny local extension that *extends* the core `post` notification
class and adds the missing key.
1. **File structure** (relative to phpBB root):
```
/ext/custom/notifications/
composer.json
ext.php
/notification/
type/
post.php
```
2. **composer.json**
```json
{
"name": "custom/notifications",
"type": "phpbb-extension",
"extra": {
"display-name": "Custom Notification Fix",
"soft-require": {
"phpbb/phpbb": ">=3.3.0"
}
}
}
```
3. **ext.php**
```php
<?php
namespace custom\notifications;
class ext extends \phpbb\extension\base {}
```
4. **notification/type/post.php** (extend the core class)
```php
<?php
namespace custom\notifications\notification\type;
use phpbb\notification\type\post as core_post;
class post extends core_post
{
/**
* {@inheritDoc}
*/
protected function get_data_for_template()
{
$data = parent::get_data_for_template();
// Ensure forum_name exists; if not, pull it from DB.
if (empty($data['forum_name']))
{
$sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . (int) $data['forum_id'];
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$data['forum_name'] = $row['forum_name'] ?? '';
}
return $data;
}
}
```
5. **Enable the extension** in the ACP → *Customise → Manage extensions*.
**Result:** The core class stays untouched; the extension will be loaded
**after** the core class (thanks to the class name collision) and will
fill the missing key only when needed. When you upgrade phpBB, the
extension stays intact.
---
### 4.3 Full core reinstall (last resort)
If you suspect many core files are corrupted (e.g., after a failed FTP
upload), simply:
1. **Download the exact same version** of phpBB you’re running from the
official site.
2. **Overwrite** every file **except** `config.php`, `cache/`, `files/`,
`store/`, and any custom extensions.
3. Run the **upgrade script** (`/install/upgrade.php`) just to be safe –
it will only apply schema changes if needed.
After a clean core, the warning should vanish, confirming that the problem
was indeed a stray/old file.
---
##
Why the “headers already sent” warning disappears
PHP can only send HTTP headers **before** any output reaches the client
(including warning messages).
```
[phpBB Debug] PHP Warning: Undefined array key "forum_name" in
...post.php on line 382
```
That warning is printed to the browser, making PHP think output has
already started. When phpBB later tries to `header('Location: ...')` or
`setcookie()`, it throws the second warning.
**Fix the first warning** → no output → headers are sent normally → second
warning disappears. No need to touch `functions.php:3076` directly.
---
##
Additional sanity‑checks after you fix it
1. **Test posting a new topic** *(as a normal user and as an admin)* to
see that notifications are created without errors.
2. **Check email notifications** (if you have SMTP enabled) – they should
contain the forum name correctly.
3. **Look at the log** – ACP → *Logs → Error log* – the warning should be
gone.
4. **Monitor the site for a few minutes** – if another “undefined array
key” appears (e.g., `topic_title`), repeat the same pattern: add a
fallback or fix the source that should supply it.
---
##
TL;DR Cheat‑sheet (copy‑paste for your notes)
```bash
# 1. Purge cache
rm -rf cache/*.php
# 2. Verify core version
grep "`$board_config['version']`" includes/constants.php
# 3. Ensure language pack is installed
# (ACP → System → Language packs → install default if missing)
# 4. Temporarily disable extensions
mv ext/yourvendor/yourext ext/yourvendor/yourext.disabled
# 5. Quick core fix (edit post.php around line 380)
# (fallback block that fetches forum_name from DB)
# 6. If you want a clean upgrade‑safe fix, create the tiny extension
# (see file list and code above)
# 7. Re‑test posting – warnings gone → headers work again
```
---
##
When you still see the warning
| Symptom | Next step |
|---------|-----------|
| Same warning after the fallback was added | Double‑check that the file
you edited is the **real** one (no duplicate in a custom theme folder).
Use `grep -R "notification/type/post.php" .` to locate every copy. |
| New warning about a *different* undefined key (e.g., `topic_title`) |
Same pattern: add a defensive fallback in the appropriate notification
class or extension. |
| No warning, but emails are still missing the forum name | The email
template may be using `{FORUM_NAME}` instead of `{forum_name}`. Edit
`styles/prosilver/template/email/post_notify.html` (or your style’s
equivalent) to use the correct variable. |
| The problem reappears after a phpBB upgrade | Re‑apply the **extension**
solution – it survives upgrades. If you edited core files, you’ll have to
redo the patch each time. |
---
### Bottom line
- The *real* bug is the missing `forum_name` in the post‑notification
data.
- Fix it (core patch **or** tiny extension) → the “headers already sent”
warning disappears.
- Keep a copy of the fix in an extension so future phpBB upgrades don’t
overwrite it.
If you run into any snags while editing the files or creating the
extension, drop the exact line(s) you’re changing here and I can review
them for you. Happy debugging!