RDF API Syntax error - php

I am using RAP API for PHP on Netbeans. There is a function named NAMESPACE located at rdf_api/api/OWLVocabulary.php and rdf_api/api/OWLVocabulary.php
and the NAMESPACE is creating a Syntax error.
function NAMESPACE()
{
return RDF_SCHEMA_URI;
}

Namespace is a reserved keyword since PHP 5.3.
You will probably find that the library you're using only works in earlier versions of PHP.
Indeed, it will have worked up to PHP 5.2:
https://3v4l.org/EUqOu

Related

Fatal error: Cannot use 'Object' as class name as it is reserved

Fatal error: Cannot use 'Object' as class name as it is reserved
I'm trying to bake my project but it shows this error.
I'm using cakephp 2.5.4 and PHP 7.0.32
I tried to change the lib folder I used the lib folder for 2.8.0
and I tried to change PHP version to 5.6.38 but nothing worked. :(
"Object" is one of the reserved keyword of PHP. You can not use it as class name. Change the class name to resolve the error.
Use Php 7.1 version. It will solve that issue
I upgraded my composer and it worked well for me.

Phppgadmin, No objects found

I am trying to get my localhost db listed in phpPgAdmin, but it says No object found phppgadmin GUI
I have already configured conf/config.inc
$conf['servers'][0]['desc'] = 'PostgreSQL'
$conf['servers'][0]['host'] = 'localhost';
$conf['servers'][0]['port'] = 5432;
$conf['owned_only'] = false;
Any help please, I have tried with Postgresql versions 9.2,9.5,10.3(not supported by phppgadmin?)
EXPLANATION OF THE PROBLEM
I see the problem! This error message is a bug in the phpPgAdmin code, which apparently has older code that was written before PHP 7.x was released.
The error in phpPgAdmin will appear if you've recently downloaded a technology stack with all of the latest versions of PHP, PostGreSQL and phpPgAdmin. For example... today's (Feb. 2019) latest versions are:
PHP 7.3.1
PostGreSQL version 11
phpPgAdmin 5.6 (Nov. 12, 2018) <= This doesn't work with PHP 7.x, but we want it to work with it and we can make it work with it!
PHP.net explains the problem in their Constructors and Destructors page:
Warning Old style constructors are DEPRECATED in PHP 7.0, and will be
removed in a future version. You should always use __construct() in
new code.
Their example is in this section on that page:
Example #2 Constructors in namespaced classes
<?php
namespace Foo;
class Bar {
public function Bar() { <- This is an older style of creating a constructor.
For PHP 7.x, it should be changed to "__construct" instead of "Bar".
// treated as constructor in PHP 5.3.0-5.3.2
// treated as regular method as of PHP 5.3.3
}
}
?>
Now that we know what the problem is, here is how to solve it.
SOLUTION
Look in your /phpPgAdmin/ folder on your web server. You should find the following files in the /classes/ sub-folder:
ArrayRecordSet.php <- Replace function ArrayRecordSet with function __construct
class.select.php <- Replace function XHtmlSimpleElement with function __construct
Gui.php <- Replace function GUI with function __construct
Misc.php <- Replace function Misc() with function __construct
Plugin.php <- Already has function __construct
PluginManager.php <- Already has function __construct
Edit those files & change any of the constructor names - which appear as duplicate class names - to __construct.
When you save those files & reload phpPgAdmin in your browser, then you will see that the "No objects found" message will have disappeared. It will then display a server name.
VoilĂ ! The latest version of phpPgAdmin 5.6 works with the latest version of PHP 7.3.1 & the latest version of PostGreSQL 11!
If you want to check the XML contents of that left tree, simply append this to your website as this is the rest of the URL, which it's using: /phppgadmin/servers.php?action=tree. That will help make debugging the phpPgAdmin code easier to do.
You can also remove the action=tree querystring parameter. Or search for it inside of the phpMyAdmin code.
BUG REPORT
I'll see about submitting a phpPgAdmin bug report to with the link to this page. Hopefully, someone will fix this error in the phpPgAdmin code base.
Have fun using the latest version of phpPgAdmin, PHP & PostGreSQL!

Use PDFlib in Laravel

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?
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();.
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();

PHPExcel not working php 5.2 AppServ

I am using php 5.2.6 in AppServ on a Windows machine and PHPExcel does not seem to work and produces no errors. I have error_reporting set to E_ALL.
On my Linux machine where I am using php 5.6 and using vagrant/homestead the same code works just fine.
Here is my code:
http://pastebin.com/6dJC8gaP
I added some echos to see where exactly it dies, and it seems to die on line 9. I had thought maybe it was an issue with php 5.2 and :: referencing, so I tried using the call_user_func, which also works on my php 5.6 but does not work on my php 5.2
http://php.net/manual/en/function.call-user-func.php
<?php
namespace Foobar;
class Foo {
static public function test() {
print "Hello world!\n";
}
}
call_user_func(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0
call_user_func(array(__NAMESPACE__ .'\Foo', 'test')); // As of PHP 5.3.0
?>
Per page:
Quote:
In PHP v5.2, you /can/ use call_user_func(array($this, 'parent::SOME_FUNCTION')).
If you don't have custom __autoload() function, you are good to go.
If you do have custom __autoload(), you need to make it `parent' aware. Something like:
Rationale: PHP 5.2 surprisingly tries to autoload a class named 'parent'. However, if you don't do anything in __autoload() for the 'parent' class, it'll work just fine.
In PHPExcel/Settings.php there are two references to libxml_disable_entity_loader function.
That function is not available until php 5.2.11, and the # in front of it was causing a silent error.
I did as they suggested and wrapped that function in function_exist checks. Everything works fine now.
Reference: https://github.com/PHPOffice/PHPExcel/issues/339

Getting an error using constants

I have a lot of pages, all of which require the file characters.php. This file contains constants which define many things in my website. They are defined like this, for example:
const $humanHEALTH = 1.1;
Everything works properly running it in my localhost using WAMP, but when I upload it to an online host I get this error:
Parse error: syntax error, unexpected T_CONST
I used phpinfo() on one of the pages and the PHP version is 5.2.17.
Any help would be greatly appreciated.
In PHP 5.2 it's define('constant_name', 'value');
Support for const outside of class definitions was not added until PHP 5.3, so your 5.2.x is too old to use this. See http://php.net/const
A constant must not have any $ sign at the beginning. Try const HUMAN_HEALTH = 1.1 instead.
As Marc B mentioned, const outside classes is only available up from PHP 5.3.
To add possible causes to those already mentioned: use of the $ character, and old PHP version; I leave this clarification from the manual that was useful to detect the problem in my case:
As opposed to defining constants using define(), constants defined
using the const keyword must be declared at the top-level scope
because they are defined at compile-time. This means that they cannot
be declared inside functions, loops, if statements or try/ catch
blocks.

Categories