Class not found exception (classes within the same project)

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

Class not found exception (classes within the same project)

Postby highcore » December 26th, 2014, 8:56 pm

Hi.

I'm trying to run Joomla 3.0 on Phalanger.

I commented out the lines that cause my previous error:
viewtopic.php?f=3&t=1417

Which, BTW, I'd like someone to help me with ;)

And I managed to compile the project successfully, but I receive a lot of "class xxx is incomplete - its base class or interface is unknown" warnings:

Image

This seems to happen for all classes in the entire project.

I can compile, but at runtime I get the following exception:

Image

Notice that the class JLogEntry IS defined and located in the same project:

Image

Can anyone please help me with this, and my previous question too?
highcore
 
Posts: 9
Joined: December 23rd, 2014, 2:14 am

Re: Class not found exception (classes within the same proje

Postby Jakub Misek » December 28th, 2014, 1:51 am

Hi,

"Class not found exception" is thrown when the file with the class is simply not included.

"class xxx is incomplete" is a warning reported by compiler, when it cannot see the base class or interface at compile-time. In such case, the base class is probably defined in a file, which is not statically included from the file containing the subclass xxx. Then compiler cannot define complete CLR type and it has to embed source code of the class xxx into the assembly and compile it at run-time when the base class is included and resolved.
Jakub Misek │ DEVSENSE s.r.o. │ Email: jakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2062
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Class not found exception (classes within the same proje

Postby highcore » December 30th, 2014, 4:49 am

Jakub Misek wrote:Hi,

"Class not found exception" is thrown when the file with the class is simply not included.

"class xxx is incomplete" is a warning reported by compiler, when it cannot see the base class or interface at compile-time. In such case, the base class is probably defined in a file, which is not statically included from the file containing the subclass xxx. Then compiler cannot define complete CLR type and it has to embed source code of the class xxx into the assembly and compile it at run-time when the base class is included and resolved.


Alright. I tried a lot of things, but I still can't get this to work.

I tried adding the entire directory structure to include_path, I tried removing all the files (from the project, but keeping them on the file system) and forcing dynamic inclusion by setting EnableStaticInclusions to false. I still can't resolve the "CLass not Found" issue.

One thing that I noticed is that if I add

Code: Select all
include "C:\........"


then it seems to be able to resolve that specific class, but I can't do that because it would mean that I have to add all the includes in each and every file (there's like 5700+ files in Joomla) because Joomla uses a customized include and discovery method, which can be found here:

https://github.com/joomla/joomla-cms/bl ... loader.php

Which means none of the files (or really very little of them) have include or require stamements.

What can I do? I need to get this running.
highcore
 
Posts: 9
Joined: December 23rd, 2014, 2:14 am

Re: Class not found exception (classes within the same proje

Postby Jakub Misek » December 30th, 2014, 8:51 pm

loader.php handles autoloading which is supported by Phalanger. try to put breakpoint into it, if it gets registered and called when a class is not found.
Jakub Misek │ DEVSENSE s.r.o. │ Email: jakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2062
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Class not found exception (classes within the same proje

Postby highcore » January 8th, 2015, 6:14 am

Jakub Misek wrote:loader.php handles autoloading which is supported by Phalanger. try to put breakpoint into it, if it gets registered and called when a class is not found.


Yes. Putting a breakpoint into PHP code in the loader.php effectively hits the breakpoint.

Furthermore, I have downloaded the Phalanger source and I can confirm that there are 4 items in the ScriptContext.SplAutoLoadFunctions:

Image

These point to the following functions:

JLoader::load
JLoader::_autoload
JLoader::loadByPsr0
JLoader::loadByAlias

I also tried to run the same exact files (from the same directory) in a regular non-Phalanger .phpproj and it works just fine.

I've been thinking about this:

what's the need for all these import features in Phalanger? I understand that the idea is to match the original PHP interpreter behavior, BUT in .Net there is a well organized project structure and and well defined unit of compilation (an assembly). IMO, php source code files that contain types which are added to a Phalanger project and their build action set to Compile should compile into proper CLR types and statically resolve needed types from the existing referenced assemblies, just like the rest of .Net languages do. This would make the entire "import" and "require" story completely secondary and would allow a proper (static) resolution of types by the compiler.

Is such a thing feasible? I'm willing to start working on it myself, then allow enabling/disabling it from the web.config, and eventually create a Pull Request to your repo.

I would need a couple of guidelines in terms of how are types resolved by the compiler. I've been examining the source lately trying to find some answers. Can you help me on this one?
highcore
 
Posts: 9
Joined: December 23rd, 2014, 2:14 am

Re: Class not found exception (classes within the same proje

Postby Jakub Misek » January 8th, 2015, 2:19 pm

The problem is, there might be more than one class definition of the same name ... and also, including has side effects such as running the code within the file ... or the file containing your class definition may be only included as a part of other files, containing some global code.

In this was, PHP behavior is preserved.
Jakub Misek │ DEVSENSE s.r.o. │ Email: jakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2062
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Class not found exception (classes within the same proje

Postby highcore » January 8th, 2015, 10:02 pm

Jakub Misek wrote:The problem is, there might be more than one class definition of the same name


Yes, however that's what namespaces are for, right? we could create an automatic namespace convention that followed the directory structure:

class Logger {... } defined in the file MyProject\Libraries\Logging\Logger.php could be compiled to MyProject.Libraries.Logging.Logger CLR type.

Jakub Misek wrote:and also, including has side effects such as running the code within the file ... or the file containing your class definition may be only included as a part of other files, containing some global code.


That's right, the include mechanism should still run for global code, however I'm talking more about the PHP classes that get compiled to CLR types. The sole fact that a file is compiled within a Visual Studio project should mean that the classes within it will be compiled to a CLR type in the output assembly, regardless of includes within the code.

Jakub Misek wrote:In this was, PHP behavior is preserved.


Yes, that's necessary as well, which is why I'm thinking to do this as a compiler option in the web.config, rather than changing the way the compiler currently works for all projects. Only the projects with this compile option would compile this way.

It's helpful and useful because I need to separate different parts of Joomla into different .Net DLLs, because otherwise I get the error related to exceeded space to store strings when compiling.

It's like taking the static compilation of Phalanger a step ahead: In addition to everything that the compiler already does for resolution of types (with includes and autoloader), it should also look into the project's referenced assemblies.

In the meantime, can you help me understand why Phalanger is not able to resolve Joomla classes, even though the loader.php is working properly?
highcore
 
Posts: 9
Joined: December 23rd, 2014, 2:14 am

Re: Class not found exception (classes within the same proje

Postby Jakub Misek » January 9th, 2015, 1:09 pm

You are right, there might be an option for that.

About the ambiguity, there might be two cases:

Code: Select all
if (A){ class X {} }
else if (B) { class X {} }

and

file1.php
Code: Select all
class X {}

file2.php
Code: Select all
class X {}


All valid in PHP, and compiler cannot know, which one will be included at runtime.
Jakub Misek │ DEVSENSE s.r.o. │ Email: jakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2062
Joined: January 4th, 2012, 2:42 pm
Location: Prague


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 2 guests

cron

User Control Panel

Login

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 62 on January 7th, 2012, 10:54 pm

Users browsing this forum: No registered users and 2 guests
Phalanger