1<?php
2get_header();
3
4$term = $wp_query->get_queried_object(); 5
6$splash_override_image_id = get_term_meta($term->term_id, '_nm_focus_splash_override_id', true);
7$splash_image_id = !empty($splash_override_image_id) ? $splash_override_image_id : get_term_meta($term->term_id, '_nm_focus_splash_id', true); // if there is an override us it, otherwise get the open graph & splash combo image
1<?php
2get_header();
3
4$term = $wp_query->get_queried_object(); 5
6$quotes = get_term_meta($term->term_id, '_nm_focus_quotes', true);
7$credits = get_term_meta($term->term_id, '_nm_focus_credits', true);
42
43 $type_category = get_child_level_child_category($post->ID); // check for child level category for display
44
45 $focus_terms = wp_get_post_terms($post->ID, 'focus'); // check for focus on the post46 $focus_tax = count($focus_terms) > 0 ? $focus_terms[0] : false;
47?>
48
40
41 $category_link = get_category_link($topLevelCategory->term_id);
42
43 $type_category = get_child_level_child_category($post->ID); // check for child level category for display44
45 $focus_terms = wp_get_post_terms($post->ID, 'focus'); // check for focus on the post
46 $focus_tax = count($focus_terms) > 0 ? $focus_terms[0] : false;
12 the_post();
13 $meta = get_post_meta($post->ID);
14
15 $email_subject = strtoupper($post->post_title);16?>
17 <!-- main posts loop -->
18 <article id="job" class="container margin-top-small margin-bottom-large">
A variable has been used but not defined, which may result in warnings during program execution. This can also cause bugs since the intended usage scope of the variable is not known.
This issue will be raised in the following cases:
if
or switch
statement but is used outside of the condition.unset()
) but is used again.$this
is used inside a static method or closure.function greetUser(string $name): string {
echo $greetings . ' ' . $name; // $greetings is not defined yet
$greetings = 'Hello';
}
function greetUser(string $name = '') {
if (is_array($name)) {
$greetings = 'Hello';
}
return $greetings . ' ' . $name; // $greetings is only defined if $name is an array, which is statically impossible due to $name's type hint
}
function greetUser(string $firstName = '', string $lastName = ''): string {
$greetings = 'Hello';
return $greetings . ' ' . $firstName . ' ' . $lastName;
}
greetUser($name, $name = 'Doe'); // $name was not defined before its first use in the first argument, and has been defined in the second argument.
The intent in the above example may have been to use the new named argument syntax introduced in PHP 8. This syntax makes use of the :
operator instead of the =
operator. You can find the documentation for this syntax in the references section.
function greetUser(string $name = '') {
$greetings = 'Hello';
if ($name === '') {
unset($greetings);
}
return $greetings . ' ' . $name; // $greetings may have been destroyed in a previous line, and statically cannot be considered valid
}
greetUser();
class User
{
public static function greet()
{
return $this->getMessage(); // $this will not work inside a static method
}
}
class User
{
public function greet()
{
$message = static function () {
return $this->getMessage(); // $this will not work inside a static closure
};
return $message;
}
}
View/template files are basically PHP code fragments. So by themselves, they don’t have enough context available for our analyzer to do its job. So it is discouraged to use analyzer on these files. Use exclude_patterns
to exlude these files/folders from the analysis.
<div>
<!-- Analyzer can't find "message" variable -->
<p><?= $message ?></p>
</div>
function greetUser(string $name): string {
$greetings = 'Hello';
echo $greetings . ' ' . $name;
}
function greetUser(string $firstName = '', string $lastName = ''): string {
$greetings = 'Hello';
return $greetings . ' ' . $firstName . ' ' . $lastName;
}
greetUser('John', 'Doe');
function greetUser(string $name = '') {
$greetings = 'Hello';
if ($name === '') {
return $greetings;
}
return $greetings . ' ' . $name;
}
greetUser();
class User
{
public function greet()
{
return $this->getMessage();
}
}
class User
{
public function greet()
{
$message = function () {
return $this->getMessage();
};
return $message;
}
}
To make this work, you'll have to add @var
PHPDoc tag throughout the view files. It'll fix the issue causing this error.
/**
* @var string $message
*/
<div>
<!-- Analyzer can't find "message" variable -->
<p><?= $message ?></p>
</div>