When is the right time to tell my advisor that I plan on leaving my PhD program? I've previously asked a question on this forum about leaving grad school and moving to a new field. I'm a chemistry PhD student in my (now) second year. I've decided to leave my PhD program because my heart is not in my work, nor am I very passionate about my field (word to the wise - don't go to graduate school because you don't know what else to do). The toll of grad school has resulted in some serious damage to my mental health to the tune of depression and anxiety. 

I don't have a fantastic relationship with my advisor, but it's not terrible either. There's a significant language and cultural barrier that creates a sort of disconnect between us. As far as I know, my advisor does not know that I plan on leaving, although if my lack of motivation and focus hasn't tipped him off that there's something wrong, I don't know what will. The emotional and physical toll of lying and not telling my advisor the truth is becoming debilitating. I can't focus on work, I spend most of my time feeling hopeless and scheming on how to get away as quickly as possible and I suffer from constant headaches. I never was so apathetic until about 3 months into grad school. 

My main concern is that I still have two classes I need to complete in the upcoming Fall semester in order to leave with my terminal master's degree, and I'm worried that if I tell my professor now he will become extremely angry, cut my funding (even thought I'll be teaching in the fall) and make me leave the lab. I do not want to leave without having something to show for my work here. However, I think I would feel better if I just told him now and put myself out of my misery. That way he would understand where I'm coming from and why I'm acting in this way. He's paying me for the summer and the guilt I have for wanting to leave is getting out of hand. 

I'm also in sort of an awkward situation where the project I'm assisting in will eventually be mine when my co-worker graduates in May and there would not be another student to take over when I leave as well. I feel like I'm just leaving my advisor out to dry.

So my primary question is, when is the best time to tell an advisor about leaving? As soon as possible? Or continue to let it sit until the fall semester starts? Is there even a "good" time to do this?
It seems to me that @Mad Jack's comment, though perhaps practical, is unethical.  Funding in a PhD program is conditional on one's intention to complete the program. If you accept funding under the expectation that you will take a certain long term action, then if you clearly realize that you no longer have the intention to complete that action then you are behaving deceptively, hence unethically, by hiding that information.  In an academic job by contrast, you sign a yearly contract.  Unless/until you have tenure, you could be dismissed at the end of any academic year.  Even when you have tenure you are rarely receiving university resources which would be wasted if you did not have a multi-year commitment, and if you do find yourself in a position of receiving those resources with the intention of leaving, then you are behaving unethically.  

(Example: most universities which offer sabbaticals view them as investments for the future of the faculty member's academic career and their career at that university.  Many universities have a policy that one has to return to "active duty" for at least one year after a sabbatical.  Violating this policy would be unethical in a similar way, although it is also more explicitly against the rules.  A yet closer unethical faculty behavior would be to receive a multi-year grant to do X, to realize after the first year that you have no intention of continuing to do research on anything at all related to X but continuing to take salary from the grant in subsequent years.)

Moreover the suggested unethical behavior is in response to hypothetical undesirable behavior by someone else.  The OP does not know that behaving unethically is necessary in order to receive the outcome which is in her personal best interest.  In fact she does not definitely know that she wants to leave the program: rather, she has some good reasons to leave (lack of interest and enthusiasm for a future academic career) and other good reasons to stay for a while (a desire to get a degree).  The right thing to do is to talk to her advisor, be candid about her doubts, and get on a track that would allow her to gracefully complete a master's degree if she so chooses.  

Someone who cuts your funding for expressing doubts about the future is not behaving ethically.  In all programs that I'm familiar with, funding is guaranteed conditional on satisfactory progress, and having a frank conversation does not make satisfactory progress unsatisfactory.  If the OP's advisor behaves so badly as to cut her funding following that conversation, then the OP can seek recourse from the director of graduate studies or the department head and has an excellent case.  The fact that she's scheduled to teach in the fall strengthens the case: if the funding is cut and she leaves because of it, who teaches the class?   

The fact that not informing the advisor is setting him up for a crisis later on is also a significant consideration.  To accept mentorship and funding from someone while planning all the while to leave them in the lurch later is quite indefensible.  I'm not surprised that the OP is having feelings of guilt about it.  As she is learning, we know deep down at a visceral level when we are doing something that we think is wrong.  Doing the right thing has intrinsic rewards -- call it karma or neuropsychology, it's true nevertheless.  I think she will sleep far better at night knowing that she did the right thing and suffered financial hardship for no fault of her own than if she did what she knew was wrong for purely selfish reasons.  I know I would.  

Finally, having a master's degree from a program and advisor who will only say negative things about you when asked is far from ideal. Being able to play well with others is valued even more in "the real world" than in academia, so burning bridges in this way is not a smart move.