Source files from Class containment


I’m not sure if it’s the right forum to ask this open question, please move it to a better place if any:

In UML you can have the definition of a Class contained in another class.
For my point of view, it’s happens when an instance of the sub-class cannot exist without an instance of the containing Class.
i.e. a Line of Invoice cannot exists without an Invoice.

So in such case I think the code of those classes can be in the same source file. Because there is no advantage to separate them in two files.
I do that in PHP (and I think also in C++ but it’s a long time ago and I’m not sure).
Do you think it’s a good idea ?

Thanks for your comments,