0

I installed PDFlib (followed the instructions PDFlib in PHP How To) on OS X by adding extension=php_pdflib.so to my php.ini file and it is loaded properly. (If I run phpinfo(); PDFlib is shown in the list.)

However if I try to use it with

$p = new PDFlib();

I get Parse error: syntax error, unexpected '$p' (T_VARIABLE)

What could cause this error?

EDIT

The error was simply caused by a missing semicolon... Now I am getting a Class 'App\Http\Controllers\PDFlib' not found which is kind of obvious cause I didn't register it in the controller with use.

I thought new PDFlib() is available for global use after installing?

2
  • Paste the surrounding lines. Most probably you have a syntax error in the previous line. Commented Aug 16, 2017 at 12:25
  • Provide complete/partial piece of code to investigate the issue cause Commented Aug 16, 2017 at 12:32

2 Answers 2

1

You're missing out the concept of namespaces. In this casePDFlib is available on the global namespace, which is \. In other words, you can either import it with use PDFlib;, or you can use it directly w/o importing it like this $p = new \PDFlib();.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you that error is gone :) If I try to initialize PDFlib now with $p = new PDFlib(); $p->set_parameter("license", "key"); I get a server error 500 and a bunch of HTML and object code in the network review.
Found this snippet in the review <span class="exception_title"><abbr title="PDFlibException">PDFlibException</abbr></span> </h3> <p class="break-long-words trace-message">License not valid for this platform</p>. Seems like the license key is not working -.- I am loosing too much hair because of that PDFlib but it seems like I rely on that.
1

now i am getting a Class 'App\Http\Controllers\PDFlib' not found.

I pretty much doubt you got PDFlib in your Controllers folder therefore it seems that your code that uses PDFlib simply lacks use to refer proper PDFlib's namespace (or you need to use fully qualified namespaces instead).

If PDFlib is not using namespace then from namespaced code youneed to use \ to reach it, i.e.:

$x = new \PDFlib();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.