-1

i want to access LINE_DOUBLE from the Border Library of phppresentation using string "LINE_DOUBLE" have tried using constant() but no luck any other solution will be very helpful

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Bullet;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Border;
use PhpOffice\PhpPresentation\Style\Fill;

 public function addLine($val)
        {
          $border = new Border;
          $str = "LINE_DOUBLE";
          $lineShape = $this->currentSlide->createLineShape($val["startX"],$val["startY"],$val["endX"],$val["endY"]);
          $lineShape->getBorder()
          ->setLineStyle(constant("$border::$str"))
          ->setLineWidth($val["width"])
          ->getColor()->setARGB($val["lineColor"]);     
        }
  • Can you try `$border::{$str}` – Ajith May 23 '21 at 16:39
  • tried already not working – user15398154 May 23 '21 at 16:41
  • @user15398154 Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include the full source code you have as a [mcve], which can be tested by others. Please see: [What Do You Mean “It Doesn't Work”?](https://meta.stackexchange.com/q/147616) – Progman May 23 '21 at 16:42
  • @user15398154 You might want to look at https://stackoverflow.com/questions/20952904/php-constant-not-working-with-namespace – Progman May 23 '21 at 17:03

2 Answers2

2

There are two ways

  1. Using constant() function
->setLineStyle(constant("Border::{$str}"))

$border is an object not class and to access the Class constant, you need Class instead of it's object

  1. Using Reflection
$ref = new ReflectionClass('Border');
->setLineStyle($ref->getConstant($str));

Let me know, if either of them works or not

Haridarshan
  • 1,898
  • 1
  • 23
  • 38
0

Just provide the full specified path of the obejct $str = "LINE_DOUBLE"; ->setLineStyle(constant("PhpOffice\PhpPresentation\Style\Border::$str"))