1--TEST-- 2Test << operator : 64bit long tests 3--SKIPIF-- 4<?php 5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); 6?> 7--FILE-- 8<?php 9 10define("MAX_64Bit", 9223372036854775807); 11define("MAX_32Bit", 2147483647); 12define("MIN_64Bit", -9223372036854775807 - 1); 13define("MIN_32Bit", -2147483647 - 1); 14 15$longVals = array( 16 MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, 17 MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, 18 MAX_64Bit -1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1 19); 20 21$otherVals = array(0, 1, -1, 7, 9, 65, -44, MAX_32Bit, MAX_64Bit); 22 23error_reporting(E_ERROR); 24 25foreach ($longVals as $longVal) { 26 foreach($otherVals as $otherVal) { 27 echo "--- testing: $longVal << $otherVal ---\n"; 28 try { 29 var_dump($longVal<<$otherVal); 30 } catch (ArithmeticError $e) { 31 echo "Exception: " . $e->getMessage() . "\n"; 32 } 33 } 34} 35 36foreach ($otherVals as $otherVal) { 37 foreach($longVals as $longVal) { 38 echo "--- testing: $otherVal << $longVal ---\n"; 39 try { 40 var_dump($otherVal<<$longVal); 41 } catch (ArithmeticError $e) { 42 echo "Exception: " . $e->getMessage() . "\n"; 43 } 44 } 45} 46 47?> 48===DONE=== 49--EXPECT-- 50--- testing: 9223372036854775807 << 0 --- 51int(9223372036854775807) 52--- testing: 9223372036854775807 << 1 --- 53int(-2) 54--- testing: 9223372036854775807 << -1 --- 55Exception: Bit shift by negative number 56--- testing: 9223372036854775807 << 7 --- 57int(-128) 58--- testing: 9223372036854775807 << 9 --- 59int(-512) 60--- testing: 9223372036854775807 << 65 --- 61int(0) 62--- testing: 9223372036854775807 << -44 --- 63Exception: Bit shift by negative number 64--- testing: 9223372036854775807 << 2147483647 --- 65int(0) 66--- testing: 9223372036854775807 << 9223372036854775807 --- 67int(0) 68--- testing: -9223372036854775808 << 0 --- 69int(-9223372036854775808) 70--- testing: -9223372036854775808 << 1 --- 71int(0) 72--- testing: -9223372036854775808 << -1 --- 73Exception: Bit shift by negative number 74--- testing: -9223372036854775808 << 7 --- 75int(0) 76--- testing: -9223372036854775808 << 9 --- 77int(0) 78--- testing: -9223372036854775808 << 65 --- 79int(0) 80--- testing: -9223372036854775808 << -44 --- 81Exception: Bit shift by negative number 82--- testing: -9223372036854775808 << 2147483647 --- 83int(0) 84--- testing: -9223372036854775808 << 9223372036854775807 --- 85int(0) 86--- testing: 2147483647 << 0 --- 87int(2147483647) 88--- testing: 2147483647 << 1 --- 89int(4294967294) 90--- testing: 2147483647 << -1 --- 91Exception: Bit shift by negative number 92--- testing: 2147483647 << 7 --- 93int(274877906816) 94--- testing: 2147483647 << 9 --- 95int(1099511627264) 96--- testing: 2147483647 << 65 --- 97int(0) 98--- testing: 2147483647 << -44 --- 99Exception: Bit shift by negative number 100--- testing: 2147483647 << 2147483647 --- 101int(0) 102--- testing: 2147483647 << 9223372036854775807 --- 103int(0) 104--- testing: -2147483648 << 0 --- 105int(-2147483648) 106--- testing: -2147483648 << 1 --- 107int(-4294967296) 108--- testing: -2147483648 << -1 --- 109Exception: Bit shift by negative number 110--- testing: -2147483648 << 7 --- 111int(-274877906944) 112--- testing: -2147483648 << 9 --- 113int(-1099511627776) 114--- testing: -2147483648 << 65 --- 115int(0) 116--- testing: -2147483648 << -44 --- 117Exception: Bit shift by negative number 118--- testing: -2147483648 << 2147483647 --- 119int(0) 120--- testing: -2147483648 << 9223372036854775807 --- 121int(0) 122--- testing: 9223372034707292160 << 0 --- 123int(9223372034707292160) 124--- testing: 9223372034707292160 << 1 --- 125int(-4294967296) 126--- testing: 9223372034707292160 << -1 --- 127Exception: Bit shift by negative number 128--- testing: 9223372034707292160 << 7 --- 129int(-274877906944) 130--- testing: 9223372034707292160 << 9 --- 131int(-1099511627776) 132--- testing: 9223372034707292160 << 65 --- 133int(0) 134--- testing: 9223372034707292160 << -44 --- 135Exception: Bit shift by negative number 136--- testing: 9223372034707292160 << 2147483647 --- 137int(0) 138--- testing: 9223372034707292160 << 9223372036854775807 --- 139int(0) 140--- testing: -9223372034707292160 << 0 --- 141int(-9223372034707292160) 142--- testing: -9223372034707292160 << 1 --- 143int(4294967296) 144--- testing: -9223372034707292160 << -1 --- 145Exception: Bit shift by negative number 146--- testing: -9223372034707292160 << 7 --- 147int(274877906944) 148--- testing: -9223372034707292160 << 9 --- 149int(1099511627776) 150--- testing: -9223372034707292160 << 65 --- 151int(0) 152--- testing: -9223372034707292160 << -44 --- 153Exception: Bit shift by negative number 154--- testing: -9223372034707292160 << 2147483647 --- 155int(0) 156--- testing: -9223372034707292160 << 9223372036854775807 --- 157int(0) 158--- testing: 2147483648 << 0 --- 159int(2147483648) 160--- testing: 2147483648 << 1 --- 161int(4294967296) 162--- testing: 2147483648 << -1 --- 163Exception: Bit shift by negative number 164--- testing: 2147483648 << 7 --- 165int(274877906944) 166--- testing: 2147483648 << 9 --- 167int(1099511627776) 168--- testing: 2147483648 << 65 --- 169int(0) 170--- testing: 2147483648 << -44 --- 171Exception: Bit shift by negative number 172--- testing: 2147483648 << 2147483647 --- 173int(0) 174--- testing: 2147483648 << 9223372036854775807 --- 175int(0) 176--- testing: -2147483649 << 0 --- 177int(-2147483649) 178--- testing: -2147483649 << 1 --- 179int(-4294967298) 180--- testing: -2147483649 << -1 --- 181Exception: Bit shift by negative number 182--- testing: -2147483649 << 7 --- 183int(-274877907072) 184--- testing: -2147483649 << 9 --- 185int(-1099511628288) 186--- testing: -2147483649 << 65 --- 187int(0) 188--- testing: -2147483649 << -44 --- 189Exception: Bit shift by negative number 190--- testing: -2147483649 << 2147483647 --- 191int(0) 192--- testing: -2147483649 << 9223372036854775807 --- 193int(0) 194--- testing: 4294967294 << 0 --- 195int(4294967294) 196--- testing: 4294967294 << 1 --- 197int(8589934588) 198--- testing: 4294967294 << -1 --- 199Exception: Bit shift by negative number 200--- testing: 4294967294 << 7 --- 201int(549755813632) 202--- testing: 4294967294 << 9 --- 203int(2199023254528) 204--- testing: 4294967294 << 65 --- 205int(0) 206--- testing: 4294967294 << -44 --- 207Exception: Bit shift by negative number 208--- testing: 4294967294 << 2147483647 --- 209int(0) 210--- testing: 4294967294 << 9223372036854775807 --- 211int(0) 212--- testing: 4294967295 << 0 --- 213int(4294967295) 214--- testing: 4294967295 << 1 --- 215int(8589934590) 216--- testing: 4294967295 << -1 --- 217Exception: Bit shift by negative number 218--- testing: 4294967295 << 7 --- 219int(549755813760) 220--- testing: 4294967295 << 9 --- 221int(2199023255040) 222--- testing: 4294967295 << 65 --- 223int(0) 224--- testing: 4294967295 << -44 --- 225Exception: Bit shift by negative number 226--- testing: 4294967295 << 2147483647 --- 227int(0) 228--- testing: 4294967295 << 9223372036854775807 --- 229int(0) 230--- testing: 4294967293 << 0 --- 231int(4294967293) 232--- testing: 4294967293 << 1 --- 233int(8589934586) 234--- testing: 4294967293 << -1 --- 235Exception: Bit shift by negative number 236--- testing: 4294967293 << 7 --- 237int(549755813504) 238--- testing: 4294967293 << 9 --- 239int(2199023254016) 240--- testing: 4294967293 << 65 --- 241int(0) 242--- testing: 4294967293 << -44 --- 243Exception: Bit shift by negative number 244--- testing: 4294967293 << 2147483647 --- 245int(0) 246--- testing: 4294967293 << 9223372036854775807 --- 247int(0) 248--- testing: 9223372036854775806 << 0 --- 249int(9223372036854775806) 250--- testing: 9223372036854775806 << 1 --- 251int(-4) 252--- testing: 9223372036854775806 << -1 --- 253Exception: Bit shift by negative number 254--- testing: 9223372036854775806 << 7 --- 255int(-256) 256--- testing: 9223372036854775806 << 9 --- 257int(-1024) 258--- testing: 9223372036854775806 << 65 --- 259int(0) 260--- testing: 9223372036854775806 << -44 --- 261Exception: Bit shift by negative number 262--- testing: 9223372036854775806 << 2147483647 --- 263int(0) 264--- testing: 9223372036854775806 << 9223372036854775807 --- 265int(0) 266--- testing: 9.2233720368548E+18 << 0 --- 267int(-9223372036854775808) 268--- testing: 9.2233720368548E+18 << 1 --- 269int(0) 270--- testing: 9.2233720368548E+18 << -1 --- 271Exception: Bit shift by negative number 272--- testing: 9.2233720368548E+18 << 7 --- 273int(0) 274--- testing: 9.2233720368548E+18 << 9 --- 275int(0) 276--- testing: 9.2233720368548E+18 << 65 --- 277int(0) 278--- testing: 9.2233720368548E+18 << -44 --- 279Exception: Bit shift by negative number 280--- testing: 9.2233720368548E+18 << 2147483647 --- 281int(0) 282--- testing: 9.2233720368548E+18 << 9223372036854775807 --- 283int(0) 284--- testing: -9223372036854775807 << 0 --- 285int(-9223372036854775807) 286--- testing: -9223372036854775807 << 1 --- 287int(2) 288--- testing: -9223372036854775807 << -1 --- 289Exception: Bit shift by negative number 290--- testing: -9223372036854775807 << 7 --- 291int(128) 292--- testing: -9223372036854775807 << 9 --- 293int(512) 294--- testing: -9223372036854775807 << 65 --- 295int(0) 296--- testing: -9223372036854775807 << -44 --- 297Exception: Bit shift by negative number 298--- testing: -9223372036854775807 << 2147483647 --- 299int(0) 300--- testing: -9223372036854775807 << 9223372036854775807 --- 301int(0) 302--- testing: -9.2233720368548E+18 << 0 --- 303int(-9223372036854775808) 304--- testing: -9.2233720368548E+18 << 1 --- 305int(0) 306--- testing: -9.2233720368548E+18 << -1 --- 307Exception: Bit shift by negative number 308--- testing: -9.2233720368548E+18 << 7 --- 309int(0) 310--- testing: -9.2233720368548E+18 << 9 --- 311int(0) 312--- testing: -9.2233720368548E+18 << 65 --- 313int(0) 314--- testing: -9.2233720368548E+18 << -44 --- 315Exception: Bit shift by negative number 316--- testing: -9.2233720368548E+18 << 2147483647 --- 317int(0) 318--- testing: -9.2233720368548E+18 << 9223372036854775807 --- 319int(0) 320--- testing: 0 << 9223372036854775807 --- 321int(0) 322--- testing: 0 << -9223372036854775808 --- 323Exception: Bit shift by negative number 324--- testing: 0 << 2147483647 --- 325int(0) 326--- testing: 0 << -2147483648 --- 327Exception: Bit shift by negative number 328--- testing: 0 << 9223372034707292160 --- 329int(0) 330--- testing: 0 << -9223372034707292160 --- 331Exception: Bit shift by negative number 332--- testing: 0 << 2147483648 --- 333int(0) 334--- testing: 0 << -2147483649 --- 335Exception: Bit shift by negative number 336--- testing: 0 << 4294967294 --- 337int(0) 338--- testing: 0 << 4294967295 --- 339int(0) 340--- testing: 0 << 4294967293 --- 341int(0) 342--- testing: 0 << 9223372036854775806 --- 343int(0) 344--- testing: 0 << 9.2233720368548E+18 --- 345Exception: Bit shift by negative number 346--- testing: 0 << -9223372036854775807 --- 347Exception: Bit shift by negative number 348--- testing: 0 << -9.2233720368548E+18 --- 349Exception: Bit shift by negative number 350--- testing: 1 << 9223372036854775807 --- 351int(0) 352--- testing: 1 << -9223372036854775808 --- 353Exception: Bit shift by negative number 354--- testing: 1 << 2147483647 --- 355int(0) 356--- testing: 1 << -2147483648 --- 357Exception: Bit shift by negative number 358--- testing: 1 << 9223372034707292160 --- 359int(0) 360--- testing: 1 << -9223372034707292160 --- 361Exception: Bit shift by negative number 362--- testing: 1 << 2147483648 --- 363int(0) 364--- testing: 1 << -2147483649 --- 365Exception: Bit shift by negative number 366--- testing: 1 << 4294967294 --- 367int(0) 368--- testing: 1 << 4294967295 --- 369int(0) 370--- testing: 1 << 4294967293 --- 371int(0) 372--- testing: 1 << 9223372036854775806 --- 373int(0) 374--- testing: 1 << 9.2233720368548E+18 --- 375Exception: Bit shift by negative number 376--- testing: 1 << -9223372036854775807 --- 377Exception: Bit shift by negative number 378--- testing: 1 << -9.2233720368548E+18 --- 379Exception: Bit shift by negative number 380--- testing: -1 << 9223372036854775807 --- 381int(0) 382--- testing: -1 << -9223372036854775808 --- 383Exception: Bit shift by negative number 384--- testing: -1 << 2147483647 --- 385int(0) 386--- testing: -1 << -2147483648 --- 387Exception: Bit shift by negative number 388--- testing: -1 << 9223372034707292160 --- 389int(0) 390--- testing: -1 << -9223372034707292160 --- 391Exception: Bit shift by negative number 392--- testing: -1 << 2147483648 --- 393int(0) 394--- testing: -1 << -2147483649 --- 395Exception: Bit shift by negative number 396--- testing: -1 << 4294967294 --- 397int(0) 398--- testing: -1 << 4294967295 --- 399int(0) 400--- testing: -1 << 4294967293 --- 401int(0) 402--- testing: -1 << 9223372036854775806 --- 403int(0) 404--- testing: -1 << 9.2233720368548E+18 --- 405Exception: Bit shift by negative number 406--- testing: -1 << -9223372036854775807 --- 407Exception: Bit shift by negative number 408--- testing: -1 << -9.2233720368548E+18 --- 409Exception: Bit shift by negative number 410--- testing: 7 << 9223372036854775807 --- 411int(0) 412--- testing: 7 << -9223372036854775808 --- 413Exception: Bit shift by negative number 414--- testing: 7 << 2147483647 --- 415int(0) 416--- testing: 7 << -2147483648 --- 417Exception: Bit shift by negative number 418--- testing: 7 << 9223372034707292160 --- 419int(0) 420--- testing: 7 << -9223372034707292160 --- 421Exception: Bit shift by negative number 422--- testing: 7 << 2147483648 --- 423int(0) 424--- testing: 7 << -2147483649 --- 425Exception: Bit shift by negative number 426--- testing: 7 << 4294967294 --- 427int(0) 428--- testing: 7 << 4294967295 --- 429int(0) 430--- testing: 7 << 4294967293 --- 431int(0) 432--- testing: 7 << 9223372036854775806 --- 433int(0) 434--- testing: 7 << 9.2233720368548E+18 --- 435Exception: Bit shift by negative number 436--- testing: 7 << -9223372036854775807 --- 437Exception: Bit shift by negative number 438--- testing: 7 << -9.2233720368548E+18 --- 439Exception: Bit shift by negative number 440--- testing: 9 << 9223372036854775807 --- 441int(0) 442--- testing: 9 << -9223372036854775808 --- 443Exception: Bit shift by negative number 444--- testing: 9 << 2147483647 --- 445int(0) 446--- testing: 9 << -2147483648 --- 447Exception: Bit shift by negative number 448--- testing: 9 << 9223372034707292160 --- 449int(0) 450--- testing: 9 << -9223372034707292160 --- 451Exception: Bit shift by negative number 452--- testing: 9 << 2147483648 --- 453int(0) 454--- testing: 9 << -2147483649 --- 455Exception: Bit shift by negative number 456--- testing: 9 << 4294967294 --- 457int(0) 458--- testing: 9 << 4294967295 --- 459int(0) 460--- testing: 9 << 4294967293 --- 461int(0) 462--- testing: 9 << 9223372036854775806 --- 463int(0) 464--- testing: 9 << 9.2233720368548E+18 --- 465Exception: Bit shift by negative number 466--- testing: 9 << -9223372036854775807 --- 467Exception: Bit shift by negative number 468--- testing: 9 << -9.2233720368548E+18 --- 469Exception: Bit shift by negative number 470--- testing: 65 << 9223372036854775807 --- 471int(0) 472--- testing: 65 << -9223372036854775808 --- 473Exception: Bit shift by negative number 474--- testing: 65 << 2147483647 --- 475int(0) 476--- testing: 65 << -2147483648 --- 477Exception: Bit shift by negative number 478--- testing: 65 << 9223372034707292160 --- 479int(0) 480--- testing: 65 << -9223372034707292160 --- 481Exception: Bit shift by negative number 482--- testing: 65 << 2147483648 --- 483int(0) 484--- testing: 65 << -2147483649 --- 485Exception: Bit shift by negative number 486--- testing: 65 << 4294967294 --- 487int(0) 488--- testing: 65 << 4294967295 --- 489int(0) 490--- testing: 65 << 4294967293 --- 491int(0) 492--- testing: 65 << 9223372036854775806 --- 493int(0) 494--- testing: 65 << 9.2233720368548E+18 --- 495Exception: Bit shift by negative number 496--- testing: 65 << -9223372036854775807 --- 497Exception: Bit shift by negative number 498--- testing: 65 << -9.2233720368548E+18 --- 499Exception: Bit shift by negative number 500--- testing: -44 << 9223372036854775807 --- 501int(0) 502--- testing: -44 << -9223372036854775808 --- 503Exception: Bit shift by negative number 504--- testing: -44 << 2147483647 --- 505int(0) 506--- testing: -44 << -2147483648 --- 507Exception: Bit shift by negative number 508--- testing: -44 << 9223372034707292160 --- 509int(0) 510--- testing: -44 << -9223372034707292160 --- 511Exception: Bit shift by negative number 512--- testing: -44 << 2147483648 --- 513int(0) 514--- testing: -44 << -2147483649 --- 515Exception: Bit shift by negative number 516--- testing: -44 << 4294967294 --- 517int(0) 518--- testing: -44 << 4294967295 --- 519int(0) 520--- testing: -44 << 4294967293 --- 521int(0) 522--- testing: -44 << 9223372036854775806 --- 523int(0) 524--- testing: -44 << 9.2233720368548E+18 --- 525Exception: Bit shift by negative number 526--- testing: -44 << -9223372036854775807 --- 527Exception: Bit shift by negative number 528--- testing: -44 << -9.2233720368548E+18 --- 529Exception: Bit shift by negative number 530--- testing: 2147483647 << 9223372036854775807 --- 531int(0) 532--- testing: 2147483647 << -9223372036854775808 --- 533Exception: Bit shift by negative number 534--- testing: 2147483647 << 2147483647 --- 535int(0) 536--- testing: 2147483647 << -2147483648 --- 537Exception: Bit shift by negative number 538--- testing: 2147483647 << 9223372034707292160 --- 539int(0) 540--- testing: 2147483647 << -9223372034707292160 --- 541Exception: Bit shift by negative number 542--- testing: 2147483647 << 2147483648 --- 543int(0) 544--- testing: 2147483647 << -2147483649 --- 545Exception: Bit shift by negative number 546--- testing: 2147483647 << 4294967294 --- 547int(0) 548--- testing: 2147483647 << 4294967295 --- 549int(0) 550--- testing: 2147483647 << 4294967293 --- 551int(0) 552--- testing: 2147483647 << 9223372036854775806 --- 553int(0) 554--- testing: 2147483647 << 9.2233720368548E+18 --- 555Exception: Bit shift by negative number 556--- testing: 2147483647 << -9223372036854775807 --- 557Exception: Bit shift by negative number 558--- testing: 2147483647 << -9.2233720368548E+18 --- 559Exception: Bit shift by negative number 560--- testing: 9223372036854775807 << 9223372036854775807 --- 561int(0) 562--- testing: 9223372036854775807 << -9223372036854775808 --- 563Exception: Bit shift by negative number 564--- testing: 9223372036854775807 << 2147483647 --- 565int(0) 566--- testing: 9223372036854775807 << -2147483648 --- 567Exception: Bit shift by negative number 568--- testing: 9223372036854775807 << 9223372034707292160 --- 569int(0) 570--- testing: 9223372036854775807 << -9223372034707292160 --- 571Exception: Bit shift by negative number 572--- testing: 9223372036854775807 << 2147483648 --- 573int(0) 574--- testing: 9223372036854775807 << -2147483649 --- 575Exception: Bit shift by negative number 576--- testing: 9223372036854775807 << 4294967294 --- 577int(0) 578--- testing: 9223372036854775807 << 4294967295 --- 579int(0) 580--- testing: 9223372036854775807 << 4294967293 --- 581int(0) 582--- testing: 9223372036854775807 << 9223372036854775806 --- 583int(0) 584--- testing: 9223372036854775807 << 9.2233720368548E+18 --- 585Exception: Bit shift by negative number 586--- testing: 9223372036854775807 << -9223372036854775807 --- 587Exception: Bit shift by negative number 588--- testing: 9223372036854775807 << -9.2233720368548E+18 --- 589Exception: Bit shift by negative number 590===DONE=== 591