Namespace in PHP file error

Discussion about the open-source Phalanger [?] project.

Namespace in PHP file error

Postby strublos » February 28th, 2013, 10:44 am

Hi, I try to move PHP application from Linux/Apache to Windows/IIS.
I setup IIS and I can call PHP file over internet browser, thats OK.
When I try use .NET features in PHP file

Code: Select all
<?php
import namespace System;
?>

I got this error

Code: Select all
CompileError (2014): Syntax error: unexpected token 'namespace' in C:\inetpub\wwwroot\webApplication\test.php on line 4, column 10.

Its possible to do this?

In web.config I have this section

Code: Select all
<phpNet>

<compiler>
  <set name="LanguageFeatures">
    <add value="PhpClr" />
  </set>
</compiler>
<classLibrary>
  <add assembly="mscorlib" />
  <add assembly="System, Version=2.0.0.0,
  Culture=neutral, PublicKeyToken=b77a5c561934e089" />

    <add url="phpLib\PhpNetPDO.dll" />
    <add url="phpLib\PhpNetMsSql.dll" />
  </classLibrary>
</phpNet>

Thank you for any suggestion
strublos
 
Posts: 3
Joined: February 25th, 2013, 12:39 pm

Re: Namespace in PHP file error

Postby Jakub Misek » February 28th, 2013, 1:56 pm

Hi,

'import namespace' is deprecated syntax used in early versions of Phalanger; in times when PHP did not have specifications for namespaces yet.

This has been removed, and Phalanger used legacy PHP syntax for namespaces now. Sadly PHP does not support importing of namespacing, just so-called 'aliasing'.

Take a look on 'use' keyword in PHP.

Thanks!
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Namespace in PHP file error

Postby strublos » February 28th, 2013, 2:45 pm

Can you post easy example of calling .NET class function from PHP file?
Something like
Code: Select all
use System;
$rnd = new Random();//create object Random from System namespace
echo $rnd.Next();


Thank you
strublos
 
Posts: 3
Joined: February 25th, 2013, 12:39 pm

Re: Namespace in PHP file error

Postby strublos » February 28th, 2013, 3:17 pm

I got It!

Code: Select all
<?php
$rnd = new System\Random;
echo $rnd->Next();
?>


Tips: print_r(get_declared_classes());
strublos
 
Posts: 3
Joined: February 25th, 2013, 12:39 pm

Re: Namespace in PHP file error

Postby Jakub Misek » February 28th, 2013, 3:29 pm

Yes, you can also use 'use' keyword to shorten your code:
Code: Select all
use System\Random;
$rnd = new Random;
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 15 guests

cron

User Control Panel

Login

Who is online

In total there are 15 users online :: 0 registered, 0 hidden and 15 guests (based on users active over the past 5 minutes)
Most users ever online was 256 on March 28th, 2024, 9:42 am

Users browsing this forum: No registered users and 15 guests