# I get an error when using \ExecuteOptions together with \usepackage{geometry}

I'm writing a custom document class. It's kinda simple, but it will use the geometry package to set page size, orientation and margins. However... Whenever I use that package, the \ExecuteOptions command stops working. Look at this minimalist testcase:

File: myclass.cls

\ProvidesClass{myclass}

\usepackage[brazilian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[a4paper,

\DeclareOption{landscape}{\geometry{landscape, top=12mm, bottom=12mm, left=15mm, right=15mm}}
\DeclareOption{portrait}{\geometry{portrait, top=15mm, bottom=15mm, left=12mm, right=12mm}}
\ExecuteOptions{portrait}
\ProcessOptions


File: doc.tex

% This works: \documentclass{myclass}
% This does not work: \documentclass[foobar]{myclass}
% This does not work: \documentclass[landscape]{myclass}
% This does not work: \documentclass[anythingITypeHere]{myclass}
\documentclass[landscape]{myclass}

\title{Simple testcase}

\begin{document}

Simple experiment... I think it should have worked.

\end{document}


Error message:

! Undefined control sequence.
\ExecuteOptions ...eserved@a \CurrentOption \@nil

l.19 \ExecuteOptions{portrait}


If I don't pass any option to the \documentclass command, then it compiles. However, if I try to pass anything (like in the example above), it fails with that weird message.

If I comment out \usepackage[...]{geometry}, and replace \geometry with something else, then it compiles. So, I'm quite sure this package is messing with \ExecuteOptions command.

If I put both \DeclareOption and \ExecuteOptions before importing the package, I get an error about undefined \geometry (as expected).

If I put \DeclareOption before the \usepackage, and leave \ExecuteOptions after it, then I get an error about importing a package inside the Options section.

So... the question is how to implement document class options while still using geometry package? In other words, how to make the above code work?

-

\DeclareOption{landscape}{\PassOptionsToPackage{landscape,top=12mm,bottom=12mm,left=15mm,right=15mm}{geometry}}
\DeclareOption{portrait}{\PassOptionsToPackage{portrait,top=15mm,bottom=15mm,left=12mm,right=12mm}{geometry}}
\ExecuteOptions{portrait}
\ProcessOptions

\RequirePackage{geometry}
\geometry{%
a4paper,