Can you start with underline?

Asked

Viewed 506 times

1

I wonder if a variable in php can begin with underline, for example: $_1teste;

3 answers

3


Yes. Yes, you can!

According to the official PHP documentation about variables:

"A valid variable name starts with a letter or underline"

Examples:

$4site = 'not yet';     // inválido; começa com um número
$_4site = 'not yet';    // válido; começa com um sublinhado
$täyte = 'mansikka';    // válido; 'ä' é um caracter ASCII (extendido) 228

1

Yes, the variables can start with a letter or underline.

For example:

// Variaveis validas;
$_variavel = 'valor';
$_2variavel = 'valor';
$_1234_vel = 'valor';

// Variaveis não validas;
$+variavel = 'valor';
$-2variavel = 'valor';
$?1234_vel = 'valor';

See you around!

1

Yes, in php these are the rules.

Consult official PHP documentation about variables:

"A valid variable name starts with a letter or underline"

Examples:

  // Variaveis validas;
   $_variavel = 'valor';
   $_2variavel = 'valor';
   $_1234_vel = 'valor';

    // Variaveis não validas;
    $+variavel = 'valor';
    $-2variavel = 'valor';
    $?1234_vel = 'valor';

See also this link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.