• More PHP vulnerabilities

    From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Thu Nov 19 16:25:33 2026
    From Newsgroup: comp.os.vms

    They released a bunch of fixes today.

    One of them is easy to demo on VMS:

    $ type another.php
    <?php

    $sslctxopts= [
    'ssl' => [
    'verify_peer'=> false,
    'verify_peer_name'=> false,
    ],
    ];
    echo file_get_contents("http://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    //echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx", false, stream_context_create($sslctxopts)) . "\n";
    echo file_get_contents("HTTPS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    echo file_get_contents("httpS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";


    $ php another.php
    Port = 80
    Port = 443
    Port = 80
    Port = 80

    WTF????

    reveal.aspx contains:

    Port = <%= Request.Url.Port %>

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Thu Nov 19 18:43:59 2026
    From Newsgroup: comp.os.vms

    On 11/19/2026 4:25 PM, Arne Vajh|+j wrote:
    They released a bunch of fixes today.

    One of them is easy to demo on VMS:

    $ type another.php
    <?php

    $sslctxopts= [
    -a-a-a 'ssl' => [
    -a-a-a-a-a-a-a 'verify_peer'=> false,
    -a-a-a-a-a-a-a 'verify_peer_name'=> false,
    -a-a-a ],
    ];
    echo file_get_contents("http://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; //echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx", false, stream_context_create($sslctxopts)) . "\n";
    echo file_get_contents("HTTPS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    echo file_get_contents("httpS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";


    $ php another.php
    Port = 80
    Port = 443
    Port = 80
    Port = 80

    WTF????

    reveal.aspx contains:

    Port = <%= Request.Url.Port %>
    Two notes:
    1) Despite the name then file_get_contents can also
    be used for POST requests (sending data out)
    2) The entire feature can be disabled in php.ini by
    setting allow_url_fopen to off, but that is not
    expected to be necessary

    Anyway I will recommend anyone needing to do HTTP requests
    in PHP to use the curl extension instead of file_get_contents.

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Fri Nov 20 07:49:40 2026
    From Newsgroup: comp.os.vms

    On 11/19/2026 4:25 PM, Arne Vajh|+j wrote:
    echo file_get_contents("http://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; //echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx", false, stream_context_create($sslctxopts)) . "\n";
    echo file_get_contents("HTTPS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    echo file_get_contents("httpS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";

    $ php another.php
    Port = 80
    Port = 443
    Port = 80
    Port = 80
    And for the curious - before fix:

    use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) && ZSTR_VAL(resource->scheme)[4] == 's';

    and after:

    use_ssl = zend_string_equals_literal_ci(resource->scheme, "https");

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Simon Clubley@clubley@remove_me.eisner.decus.org-Earth.UFP to comp.os.vms on Fri Nov 20 20:10:56 2026
    From Newsgroup: comp.os.vms

    On 2026-11-20, Arne Vajhoj <arne@vajhoej.dk> wrote:
    On 11/19/2026 4:25 PM, Arne Vajhoj wrote:
    echo file_get_contents("http://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    //echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >> echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx", false,
    stream_context_create($sslctxopts)) . "\n";
    echo file_get_contents("HTTPS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    echo file_get_contents("httpS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";

    $ php another.php
    Port = 80
    Port = 443
    Port = 80
    Port = 80
    And for the curious - before fix:

    use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) && ZSTR_VAL(resource->scheme)[4] == 's';


    I really hope that line was always compiled by a short-circuiting
    compiler and that line always successfully triggered short-circuiting...

    Don't be surprised if everyone is now looking for similar constructs
    that rely on short-circuiting to be safe.

    And yes, I know it's read-only. That's not the point. That's _seriously_
    not the point.

    Simon.
    --
    Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
    Walking destinations on a map are further away than they appear.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Fri Nov 20 15:24:05 2026
    From Newsgroup: comp.os.vms

    On 11/20/2026 3:10 PM, Simon Clubley wrote:
    On 2026-11-20, Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 11/19/2026 4:25 PM, Arne Vajh|+j wrote:
    echo file_get_contents("http://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
    //echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>> echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx", false,
    stream_context_create($sslctxopts)) . "\n";
    echo file_get_contents("HTTPS://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>> echo file_get_contents("httpS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";

    $ php another.php
    Port = 80
    Port = 443
    Port = 80
    Port = 80
    And for the curious - before fix:

    use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) &&
    ZSTR_VAL(resource->scheme)[4] == 's';

    I really hope that line was always compiled by a short-circuiting
    compiler and that line always successfully triggered short-circuiting...

    Don't be surprised if everyone is now looking for similar constructs
    that rely on short-circuiting to be safe.
    Doesn't C require/mandate short circuiting in cases like this??

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.os.vms on Fri Nov 20 20:28:25 2026
    From Newsgroup: comp.os.vms

    In article <11dqa7g$3guqc$1@dont-email.me>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 11/20/2026 3:10 PM, Simon Clubley wrote:
    On 2026-11-20, Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 11/19/2026 4:25 PM, Arne Vajh|+j wrote:
    echo file_get_contents("http://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>>> //echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>>> echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx", false, >>>> stream_context_create($sslctxopts)) . "\n";
    echo file_get_contents("HTTPS://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>>> echo file_get_contents("httpS://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>>
    $ php another.php
    Port = 80
    Port = 443
    Port = 80
    Port = 80
    And for the curious - before fix:

    use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) &&
    ZSTR_VAL(resource->scheme)[4] == 's';

    I really hope that line was always compiled by a short-circuiting
    compiler and that line always successfully triggered short-circuiting...

    Don't be surprised if everyone is now looking for similar constructs
    that rely on short-circuiting to be safe.

    Doesn't C require/mandate short circuiting in cases like this??

    Yes. `&&` and `||` are both short-circuiting operators in C and
    have always been so.

    - Dan C.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Sat Nov 21 17:32:01 2026
    From Newsgroup: comp.os.vms

    On 11/20/2026 3:24 PM, Arne Vajh|+j wrote:
    On 11/20/2026 3:10 PM, Simon Clubley wrote:
    On 2026-11-20, Arne Vajh|+j <arne@vajhoej.dk> wrote:
    And for the curious - before fix:

    use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) &&
    ZSTR_VAL(resource->scheme)[4] == 's';

    I really hope that line was always compiled by a short-circuiting
    compiler and that line always successfully triggered short-circuiting...

    Don't be surprised if everyone is now looking for similar constructs
    that rely on short-circuiting to be safe.

    Doesn't C require/mandate short circuiting in cases like this??
    I believe the VMS landscape looks like:

    Undefined(*) L to R L to R
    all short circuit
    VMS Fortran .and.
    .or.
    VMS Pascal and and_then
    or or_else
    C & &&
    | ||
    Ada and and then
    or or else
    Java & &&
    | ||
    Python & and
    | or
    PHP & &&
    | ||
    and(**)
    or(**)

    *) do not use with anything with side effects
    **) do not use ever

    Example of undefined with VMS Pascal and /OPT vs /NOOPT:

    $ type demo.pas
    program demo(input,output);

    function ff : boolean;

    begin
    writeln('ff');
    ff := false;
    end;

    function tf : boolean;

    begin
    writeln('tf');
    tf := true;
    end;

    var
    res : boolean;

    begin
    res := ff and tf;
    writeln('ff and tf', res);
    res := ff and_then tf;
    writeln('ff and_then tf', res);
    res := tf or ff;
    writeln('tf or ff', res);
    res := tf or_else ff;
    writeln('tf or_else ff', res);
    end.
    $ pas demo
    $ lin demo
    $ r demo
    ff
    ff and tf FALSE
    ff
    ff and_then tf FALSE
    tf
    tf or ff TRUE
    tf
    tf or_else ff TRUE
    $ pas/noop demo
    $ lin demo
    $ r demo
    ff
    tf
    ff and tf FALSE
    ff
    ff and_then tf FALSE
    tf
    ff
    tf or ff TRUE
    tf
    tf or_else ff TRUE

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Sat Nov 21 17:49:52 2026
    From Newsgroup: comp.os.vms

    On 11/21/2026 5:32 PM, Arne Vajh|+j wrote:
    PHP-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a &-a-a-a-a-a-a-a-a &&
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a |-a-a-a-a-a-a-a-a ||
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a and(**)
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a or(**)

    **) do not use ever
    And in case somebody wonder.

    $ php crazy.php
    False
    True
    True False
    $ clean
    $ type crazy.php
    <?php

    $a = True;
    $b = False;
    $c = $a && $b;
    echo sprintf("%s\n", $c ? 'True' : 'False');
    $c = $a and $b;
    echo sprintf("%s\n", $c ? 'True' : 'False');
    $c2 = ($c1 = $a and $b);
    echo sprintf("%s %s\n", $c1 ? 'True' : 'False', $c2 ? 'True' : 'False');


    $ php crazy.php
    False
    True
    True False

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.os.vms on Sat Nov 21 23:58:24 2026
    From Newsgroup: comp.os.vms

    In article <6b021bab$0$672$14726298@news.sunsite.dk>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 11/20/2026 3:24 PM, Arne Vajh|+j wrote:
    On 11/20/2026 3:10 PM, Simon Clubley wrote:
    [snip]
    Doesn't C require/mandate short circuiting in cases like this??

    I believe the VMS landscape looks like:

    Undefined(*) L to R L to R
    all short circuit
    [snip]
    VMS Fortran .and.
    .or.
    VMS Pascal and and_then
    or or_else
    C & &&
    | ||
    Ada and and then
    or or else
    Java & &&
    | ||
    Python & and
    | or
    PHP & &&
    | ||
    and(**)
    or(**)
    [snip]

    For C, Java, Python, and (probably?) PHP, you are mixing up
    different categories of operators: `&` and `|` are bitwise
    operators in those languages, while `&&` and `||` are boolean
    operators. Since they are intended to do differnt things, the
    semantics are different.

    I doubt that there are many many languages that would introduce short-circuiting behavior for bitwise operators. But note also
    that we may see behaviors like this:

    ```c
    #include <stdio.h>
    int
    main(void)
    {
    int a = 1, b = 2;

    if (a)
    printf("a is true\n");
    if (b)
    printf("b is true\n");
    if (a & b)
    printf("both are true\n");
    else
    printf("but `&` is not a boolean operator\n");

    return 0;
    }
    ```

    Moral of the story: don't lump boolean and bitwise operators
    together like they are the same thing.

    - Dan C.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.os.vms on Sun Nov 22 01:13:35 2026
    From Newsgroup: comp.os.vms

    On Sat, 21 Nov 2026 17:32:01 -0500, Arne Vajh|+j wrote:

    PHP & &&
    | ||
    and(**)
    or(**)

    **) do not use ever

    How many things are there in PHP that one might classify as rCLdo not
    use everrCY?

    HererCOs another one: rCL+rCY on arrays. Yes, itrCOs defined. Defined as what? --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Sat Nov 21 20:25:26 2026
    From Newsgroup: comp.os.vms

    On 11/21/2026 6:58 PM, Dan Cross wrote:
    In article <6b021bab$0$672$14726298@news.sunsite.dk>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 11/20/2026 3:24 PM, Arne Vajh|+j wrote:
    On 11/20/2026 3:10 PM, Simon Clubley wrote:
    [snip]
    Doesn't C require/mandate short circuiting in cases like this??

    I believe the VMS landscape looks like:

    Undefined(*) L to R L to R
    all short circuit
    [snip]
    VMS Fortran .and.
    .or.
    VMS Pascal and and_then
    or or_else
    C & &&
    | ||
    Ada and and then
    or or else
    Java & &&
    | ||
    Python & and
    | or
    PHP & &&
    | ||
    and(**)
    or(**)
    [snip]

    For C, Java, Python, and (probably?) PHP, you are mixing up
    different categories of operators: `&` and `|` are bitwise
    operators in those languages, while `&&` and `||` are boolean
    operators. Since they are intended to do differnt things, the
    semantics are different.

    Those 4 are a bit different.

    Java has both bitwise & and | on integer types and logical & and | on
    booleans.

    In C and Python bool are sort of an int so bitwise and logical
    are the same.

    PHP just auto converts booleans to ints for bitwise operator.

    But all 4 quacks like a duck.

    I doubt that there are many many languages that would introduce short-circuiting behavior for bitwise operators. But note also
    that we may see behaviors like this:

    ```c
    #include <stdio.h>
    int
    main(void)
    {
    int a = 1, b = 2;

    if (a)
    printf("a is true\n");
    if (b)
    printf("b is true\n");
    if (a & b)
    printf("both are true\n");
    else
    printf("but `&` is not a boolean operator\n");

    return 0;
    }
    ```
    Good point.

    The problem here is the use of int instead of bool.

    #include <stdio.h>
    #include <stdbool.h>

    int main()
    {
    bool a = 1, b = 2;

    if (a)
    printf("a is true\n");
    if (b)
    printf("b is true\n");
    if (a & b)
    printf("both are true\n");
    else
    printf("but `&` is not a boolean operator\n");

    return 0;
    }

    Outputs a different result.

    But treating int's as booleans is an integrated part
    of C.

    And it has spilled over to many other languages.

    So yes - if working with int's instead of bool's,
    then bitwise operators can not be used as logical
    operators.

    Arne




    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Sat Nov 21 20:38:37 2026
    From Newsgroup: comp.os.vms

    On 11/21/2026 8:13 PM, Lawrence DrCOOliveiro wrote:
    On Sat, 21 Nov 2026 17:32:01 -0500, Arne Vajh|+j wrote:

    PHP & &&
    | ||
    and(**)
    or(**)

    **) do not use ever

    How many things are there in PHP that one might classify as rCLdo not
    use everrCY?

    Several.

    HererCOs another one: rCL+rCY on arrays. Yes, itrCOs defined. Defined as what?

    It merges arrays. With slightly different semantics than array_merge.

    I think it mostly makes sense for associative arrays. It is weird for
    indexed arrays.

    $ type crazy2.php
    <?php

    $a = [ 'A' => 1, 'B' => 2, 'C' => 3 ];
    $b = [ 'C' => 4, 'D' => 5 ];
    $c = $a + $b;
    print_r($c);
    $d = array_merge($a, $b);
    print_r($d);


    $ php crazy2.php
    Array
    (
    [A] => 1
    [B] => 2
    [C] => 3
    [D] => 5
    )
    Array
    (
    [A] => 1
    [B] => 2
    [C] => 4
    [D] => 5
    )

    $ type crazy3.php
    <?php

    $a = [ 'A' ];
    $b = [ 'B', 'C' ];
    $c = $a + $b;
    print_r($c);
    $d = array_merge($a, $b);
    print_r($d);


    $ php crazy3.php
    Array
    (
    [0] => A
    [1] => C
    )
    Array
    (
    [0] => A
    [1] => B
    [2] => C
    )

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.os.vms on Sun Nov 22 01:47:44 2026
    From Newsgroup: comp.os.vms

    On Sat, 21 Nov 2026 20:25:26 -0500, Arne Vajh|+j wrote:

    Java has both bitwise & and | on integer types and logical & and |
    on booleans.

    In C and Python bool are sort of an int so bitwise and logical are
    the same.

    Python treats bool as a subclass of int. (Yes, you can subclass int.)

    Java tries to treat them as entirely separate types, which is not
    necessarily a bad thing on its own, but then it doesnrCOt provide
    natural conversions between them. Like being able to use bool for
    indexing arrays, just for example.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Sat Nov 21 20:55:41 2026
    From Newsgroup: comp.os.vms

    On 11/21/2026 8:47 PM, Lawrence DrCOOliveiro wrote:
    On Sat, 21 Nov 2026 20:25:26 -0500, Arne Vajh|+j wrote:

    Java has both bitwise & and | on integer types and logical & and |
    on booleans.

    In C and Python bool are sort of an int so bitwise and logical are
    the same.

    Python treats bool as a subclass of int. (Yes, you can subclass int.)

    Java tries to treat them as entirely separate types, which is not
    necessarily a bad thing on its own,

    We are some that like type safety.

    :-)

    but then it doesnrCOt provide
    natural conversions between them. Like being able to use bool for
    indexing arrays, just for example.

    It would have to be a[bv ? 1 : 0] or use a Map<Boolean,X> instead
    of X[].

    Arne

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.os.vms on Sun Nov 22 05:43:09 2026
    From Newsgroup: comp.os.vms

    In article <11dtg8h$isan$1@dont-email.me>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 11/21/2026 6:58 PM, Dan Cross wrote:
    In article <6b021bab$0$672$14726298@news.sunsite.dk>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 11/20/2026 3:24 PM, Arne Vajh|+j wrote:
    On 11/20/2026 3:10 PM, Simon Clubley wrote:
    [snip]
    Doesn't C require/mandate short circuiting in cases like this??

    I believe the VMS landscape looks like:

    Undefined(*) L to R L to R
    all short circuit
    [snip]
    VMS Fortran .and.
    .or.
    VMS Pascal and and_then
    or or_else
    C & &&
    | ||
    Ada and and then
    or or else
    Java & &&
    | ||
    Python & and
    | or
    PHP & &&
    | ||
    and(**)
    or(**)
    [snip]

    For C, Java, Python, and (probably?) PHP, you are mixing up
    different categories of operators: `&` and `|` are bitwise
    operators in those languages, while `&&` and `||` are boolean
    operators. Since they are intended to do differnt things, the
    semantics are different.

    Those 4 are a bit different.

    Java has both bitwise & and | on integer types and logical & and | on >booleans.

    Eh...kinda. It's true that Java has well-defined bitwise
    operators on booleans, but it's really just expressing the
    integer rules for a type that can only have two values. It's
    still a bitwise-operation.

    In C and Python bool are sort of an int so bitwise and logical
    are the same.

    PHP just auto converts booleans to ints for bitwise operator.

    But all 4 quacks like a duck.

    I doubt that there are many many languages that would introduce
    short-circuiting behavior for bitwise operators. But note also
    that we may see behaviors like this:

    ```c
    #include <stdio.h>
    int
    main(void)
    {
    int a = 1, b = 2;

    if (a)
    printf("a is true\n");
    if (b)
    printf("b is true\n");
    if (a & b)
    printf("both are true\n");
    else
    printf("but `&` is not a boolean operator\n");

    return 0;
    }
    ```

    Good point.

    The problem here is the use of int instead of bool.

    Incorrect.

    #include <stdio.h>
    #include <stdbool.h>

    int main()
    {
    bool a = 1, b = 2;

    This does not do what you think that it does.

    if (a)
    printf("a is true\n");
    if (b)
    printf("b is true\n");
    if (a & b)
    printf("both are true\n");
    else
    printf("but `&` is not a boolean operator\n");

    return 0;
    }

    Outputs a different result.

    Because in this case, `a` and `b` are both equal to (integer) 1.
    The assignment `bool b = 2` sets `b` to `true` (any non-zero
    integer constant is "true" in a boolean context in C), and
    `true` has the value 1 (C23, sec 6.4.4.6, para 3).

    An object of type `bool` in C has exactly one value-holding bit,
    and `sizeof(bool)*CHAR_BIT-1` padding bits (C23, sec 6.2.6.2,
    para 1).

    When applied to a bitwise operator like `&` or `|`, both `a` and
    `b` will first be converted to a (signed) `int` based on the
    rank of the `bool` type and the rules for integer promotions
    (C23, sec 6.3.1.1).

    ```
    term% cat bitwise.c
    #include <stdbool.h>
    #include <stdio.h>
    int
    main(void)
    {
    bool a = 1, b = 2;
    if (a)
    printf("a is true\n");
    if (b)
    printf("b is true\n");
    if (a & b)
    printf("both are true (a = %d, b = %d)\n", a, b);
    else
    printf("but `&` is not a boolean operator\n");
    return 0;
    }
    term% make bitwise
    cc -O2 -pipe -o bitwise bitwise.c
    term% ./bitwise
    a is true
    b is true
    both are true (a = 1, b = 1)
    term%
    ```

    But treating int's as booleans is an integrated part
    of C.

    In C, `bool` is an integer type. The usual arithmetic
    conversions apply, including the integer promotion rules.

    And it has spilled over to many other languages.

    So yes - if working with int's instead of bool's,
    then bitwise operators can not be used as logical
    operators.

    No. In all cases, bitwise operators are doing bitwise
    operations. They are simply not boolean operators, even if
    applied to boolean values.

    - Dan C.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Bill Gunshannon@bill.gunshannon@gmail.com to comp.os.vms on Sun Nov 22 08:27:14 2026
    From Newsgroup: comp.os.vms

    On 11/21/26 20:13, Lawrence DrCOOliveiro wrote:
    On Sat, 21 Nov 2026 17:32:01 -0500, Arne Vajh|+j wrote:

    PHP & &&
    | ||
    and(**)
    or(**)

    **) do not use ever

    How many things are there in PHP that one might classify as rCLdo not
    use everrCY?

    The whole language?


    HererCOs another one: rCL+rCY on arrays. Yes, itrCOs defined. Defined as what?



    bill

    --- Synchronet 3.22a-Linux NewsLink 1.2